web-dev-qa-db-ja.com

カスタム分類用語ごとのカスタム投稿タイプアーカイブトピックプレート

カスタム投稿タイプのカスタム分類用語の対応するテンプレートを使用して、すべての投稿を一覧表示します。理解しやすくするために:

カスタム投稿タイプはPUBLICATIONSと呼ばれ、LISTSというカスタム分類があります。各リストテンプレートは若干異なります。したがって、すべての投稿がarchive-publicationsページにリストされている場合、LIST Aという用語の投稿はテンプレートA、LIST B、テンプレートBなどを使用して表示されます。

私はこれを試してみました:

<?php
function publikationen_archive() {
    if ( is_archive('publikationen') && is_tax('downloads') ) { get_template_part( 'templates/content-downloads' );
    } elseif ( is_archive('publikationen') && is_tax('sonderbaende-kataloge') ) { 
    get_template_part( 'templates/content-sonderbaende-kataloge' );
    } elseif ( is_archive('publikationen') && is_tax('neuerscheinungen') ) { 
    get_template_part( 'templates/content-neuerscheinungen' );
    } elseif ( is_archive('publikationen') && is_tax('untersuchungen') ) { 
    get_template_part( 'templates/content-untersuchungen' );
    } elseif ( is_archive('publikationen') && is_tax('studien-materialien') ) { 
    get_template_part( 'templates/content-studien-materialien' );
    }
} ?>

うまくいきませんでした。それから私はフィルタsingle_templatetemplate_redirectおよびtemplate_includeに出会いました、しかし、それらをどうするべきか本当に知りません。

1
gfaw

解決しました

溶液:

<?php 
if ( has_term( 'downloads', 'listen', $post->ID ) ) {
    get_template_part( 'templates/content-downloads-vergriffener-baende' ); 
} 
elseif ( has_term( 'untersuchungen', 'listen', $post->ID ) ) { 
    get_template_part( 'templates/content-untersuchungen' ); 
} 
elseif ( has_term( 'studien-materialien', 'listen', $post->ID ) ) { 
    get_template_part( 'templates/content-studien-materialien' ); 
} 
elseif ( has_term( 'sonderbaende-kataloge', 'listen', $post->ID ) ) { 
    get_template_part( 'templates/content-sonderbaende-kataloge' ); 
}
?>

この投稿: http://wpquestions.com/question/show/id/2038 はその過程で非常に役に立ちました。

1
gfaw

ポストループで。このコードを使ってください。

<?php while (have_posts()) : the_post(); 
            $post_type = get_post_type(get_the_ID());
            if($post_type !='post'){
                get_template_part('content-' . $post_type, get_post_format());
            }
            else {
               get_template_part( 'content', get_post_format() );
            }
            //If comments are open or we have at least one comment, load up the comment template.
                    // if ( comments_open() || get_comments_number() ) {
                    //  comments_template( '', true );
                    // }
                //endwhile; ?>
            <?php comments_template( '', true ); ?>
        <?php endwhile; // end of the loop. ?>

投稿タイプのページ構造に合わせてcontent-publication.phpを作成します。

0
Lemon Kazi