フォルダでget_template_part()を使用する方法があるかどうか疑問に思っていますか?すべての再利用可能な要素を個別のファイルに入れるため、メインフォルダーには多くのファイルがあります。それからフォルダに入れたいです。
Codexにはそれに関する情報はありません:http : //codex.wordpress.org/Function_Reference/get_template_part
フォルダでget_template_part()を使用する方法があるかどうか疑問に思っていますか?すべての再利用可能な要素を個別のファイルに入れるため、メインフォルダーには多くのファイルがあります。それからフォルダに入れたいです。
Codexにはそれに関する情報はありません:http : //codex.wordpress.org/Function_Reference/get_template_part
回答:
実際には、あなたが、私はと呼ばれる私のテーマディレクトリ内のフォルダ持つことができます/partials/そのフォルダ内には、私は、次のようなファイルを持っているlatest-articles.php、latest-news.phpとlatest-statements.php私は使用してこれらのファイルをロードするget_template_part()ように:
get_template_part('partials/latest', 'news');
get_template_part('partials/latest', 'articles');
get_template_part('partials/latest', 'statements');
.phpファイル名からを省略することを忘れないでください。
<?php get_template_part('partials/file'); ?>
                    そうではないと思います。codexで知りたいことではない場合は、ソースへのリンクをたどって、コードを確認し、管理してみてください。
見てみると、get_template_part関数は次のように定義されています。
function get_template_part( $slug, $name = null ) {
    do_action( "get_template_part_{$slug}", $slug, $name );
    $templates = array();
    if ( isset($name) )
        $templates[] = "{$slug}-{$name}.php";
    $templates[] = "{$slug}.php";
    locate_template($templates, true, false);
}
これから、get_template_part関数が目的のphpファイル名を作成し、関数Locate_templateを呼び出すだけであることがわかります。これは役に立たないので、locate_template関数も調べました。
function locate_template($template_names, $load = false, $require_once = true ) {
    $located = '';
    foreach ( (array) $template_names as $template_name ) {
        if ( !$template_name )
            continue;
        if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
            $located = STYLESHEETPATH . '/' . $template_name;
            break;
        } else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
            $located = TEMPLATEPATH . '/' . $template_name;
            break;
        }
    }
    if ( $load && '' != $located )
        load_template( $located, $require_once );
    return $located;
}
get_template_partから呼び出されたphpファイルの検索テンプレート検索を取得します。ただし、コードから直接Locate_templateを呼び出すことができます。そしてこれは便利です。
get_template_part( 'loop-sigle.php')関数の代わりにこのコードを試してください(ファイルはテーマ内のmydirにあります):
locate_template( 'mydir/loop-single.php', true, true );機能のメモはget_template_part()言う:
注
-使用:Locate_template()
-使用:do_action() 'get_template_part _ {$ slug}'アクションを呼び出します。
Wichでは、次のように使用できますlocate_template()。
TEMPLATEPATHの前にSTYLESHEETPATHを検索して、親テーマから継承するテーマが1つのファイルをオーバーロードできるようにします。
TEMPLATEPATH使用するサブディレクトリを定義すると、サブディレクトリget_template_part()内のファイルが検索されます。