2017-05-20 1 views
0

私はACFを使用していますが、カテゴリに応じて異なる方法で投稿を表示したいと思います。ここにある私のシングル:Wordpressはif文が両方のテンプレートを表示するテンプレート部分を取得します

<?php if(!function_exists('get_field')) return; ?> 

<article> 
    <!-- different content here --> 
</article> 

私はカテゴリ「関係書類」との記事に行く、それは両方のロード:

<?php get_header(); ?> 
<?php if(!function_exists('get_field')) return; ?> 

<main class="main_flex"> 
    <?php if (have_posts()) : ?> 
    <?php while (have_posts()) : the_post(); 
     if (in_category('dossiers')) { get_template_part('single_dossier'); 
     } else { get_template_part('template-parts/content', 'single'); 
     } ?> 
    <article> 
    <!-- content here --> 
    </article> 
    <?php endwhile; ?> 
    <?php endif; ?> 
</main> 
<?php get_footer(); ?> 

そして、私はsingle_dossier.phpという名前のファイルに、私はこれを書いた

内容私が間違ったやり方を教えてくれる人は誰ですか? ありがとう!

答えて

0

あなたのパーマリンクの構造によっては、同じid/slugの投稿が2つあることがあります。チェックのために

この使用このコード:

<?php get_header(); ?> 
<?php if(!function_exists('get_field')) return; ?> 

<main class="main_flex"> 
    <?php if (have_posts()) : ?> 
    <?php $x = 0; ?> 
    <?php while (have_posts()) : the_post(); 
     $x++; 
     echo '{{' . $x . ':' . $post->ID . '}}'; 
     if (in_category('dossiers')) { get_template_part('single_dossier'); 
     } else { get_template_part('template-parts/content', 'single'); 
     } ?> 
    <article> 
    <!-- content here --> 
    </article> 
    <?php endwhile; ?> 
    <?php endif; ?> 
</main> 
<?php get_footer(); ?> 

そして、あなたは出力に入るかどうかを確認してみましょう{{1:someID}} & {{2:someAnotherID}}。

または、次のコードを使用します。

<?php get_header(); ?> 
<?php if(!function_exists('get_field')) return; ?> 

<main class="main_flex"> 
    <?php if (have_posts()) : ?> 
    <?php 
     the_post(); 
     if (in_category('dossiers')) { get_template_part('single_dossier'); 
     } else { get_template_part('template-parts/content', 'single'); 
     } ?> 
    <article> 
    <!-- content here --> 
    </article> 
    <?php endif; ?> 
</main> 
<?php get_footer(); ?> 
+0

こんにちは! {{2:1815}}それはどういう意味ですか? – Soph87

+0

@ Soph87そして、最初は何ですか? {{1:???}}。その意味私の推測は正しい:)あなたは同じIDまたはスラッグリンクを持つ2つの記事を持っています。 –

+0

これは奇妙なことですが、{{1:XXXX}}はありません。どのようなアイデアを...... ......? – Soph87

関連する問題