2016-04-11 25 views
0

Wordpressでget_next_postで使用されるカテゴリを設定することは可能ですか?Wordpress get_next_postカテゴリを設定する

私は複数のカテゴリを持つことができる投稿を持っています。

投稿を表示しているsingle.phpページに、次の投稿と前の投稿を表示します。

私はので、私はどのように使うのですか私はsingle.phpの中から選択するカテゴリを持っている私は、マニュアルを参照してくださいとしてget_next_post

$the_cat = 'latest'; 

    $next_post = get_next_post($in_same_term = true, $excluded_terms = '', $taxonomy = $the_cat); 

答えて

0

でありません。

$分類法 (文字列)(オプション)$ in_same_termがtrueの場合の分類法。 WordPress 3.8で追加されました。 デフォルト:「カテゴリ」

私は見ての通り、あなたがfalseに$in_same_termを設定した場合、その後、あなたは$taxonmyを変更することができます。

私は、それがテストされていないあなたのための回避策、単なるアイデアかもしれないと思う:あなたのページのループの中で、それはコーデックスhttps://codex.wordpress.org/Function_Reference/get_next_postに言うことで、次の

<?php 
while ($next_post = get_next_post()) { 
    if (!empty($next_post) && $next_post->catID == 'what you want') { 
     ?> 
     <a href="<?php echo get_permalink($next_post->ID); ?>"><?php echo $next_post->post_title; ?></a>  
     <?php 
    } 
} 
?> 
0

...

。その後、..

$category = get_the_category(); 
$category_name = $category[0]->name: 

そして...

$next_post = get_next_post(true, null, $category_name); 
0123を経由してあなたの次のポストを得ます
関連する問題