2016-07-08 7 views
0

**更新(ちょっとした不具合を含む)...カスタム分類法をページナビゲーションとして使用する

分類法の用語をエコーし​​てコードを取得しました。ちょっとしたものがあります。 1つ以上の用語を選択することはできません。それ以外は何をすべきか分からない。ここにコードがあります。誰かが複数の分類用語でこれを行う方法を知っている場合は

<?php // get_posts in same custom taxonomy 
        $postlist_args = array(
        'posts_per_page' => -1, 
        'orderby'   => '', 
        'order'   => 'ASC', 
        'post_type'  => 'YOUR_POST_TYPE_HERE', 
        'YOUR_TERM_HERE'   => array($term->slug) // here is your echo 

       ); 
        $postlist = get_posts($postlist_args);  
        // get ids of posts retrieved from get_posts 
        $ids = array(); 
        foreach ($postlist as $thepost) { 
        $ids[] = $thepost->ID; 
        } 

        // get and echo previous and next post in the same taxonomy   
        $thisindex = array_search($post->ID, $ids); 
        $previd = $ids[$thisindex-1]; 
        $nextid = $ids[$thisindex+1]; 
        if (!empty($nextid)) { 
        echo '<a rel="next" href="' . get_permalink($nextid). '"><i class="fa fa-chevron-circle-left" aria-hidden="true"></i></a>'; 
        } 
        if (!empty($previd)) { 
        echo '<a rel="prev" href="' . get_permalink($previd). '"><i class="fa fa-chevron-circle-right" aria-hidden="true"></i></a>'; 
        } ;?> 

<?php $my_terms = get_the_terms($post->ID, 'YOUR_TERM_HERE'); 
if($my_terms && !is_wp_error($my_terms)) { 
    foreach($my_terms as $term) {} 
} ;?> 

セットアップあなたのページナビゲーション:

は、エコーのための準備期間を取得します。私は本当に知りたいです。

これはおそらく説明するのが難しいかもしれませんが、私は最善を尽くします。

私はカスタムポストタイプabout usを得て、そのCPTでは階層カスタム分類タイルour teamを作成しました。私はそのカスタムタクソノミーにいくつかの項目を追加しました。私がやろうとしています何

  • チームのメンバー1
  • チームのメンバー2
  • など

あなたはチームのメンバー1をクリックしたときに表示されるフィールド(DIV)があるでしょうですチームメンバー2の名前をクリックすると、次のチームメンバーに行くことができます。

それBU何かが、それはpost_typeトラフ行くカスタム分類スルー行かないんのこの種:

<?php // get_posts in same custom taxonomy 
$postlist_args = array(
    'posts_per_page' => -1, 
    'orderby'   => 'menu_order title', 
    'order'   => 'ASC', 
    'post_type'  => 'over-ons', 
    'taxonomy' => 'ons_team' 
); 
$postlist = get_posts($postlist_args); 

// get ids of posts retrieved from get_posts 
$ids = array(); 
foreach ($postlist as $thepost) { 
    $ids[] = $thepost->ID; 
} 

// get and echo previous and next post in the same taxonomy   
$thisindex = array_search($post->ID, $ids); 
$previd = $ids[$thisindex-1]; 
$nextid = $ids[$thisindex+1]; 
if (!empty($previd)) { 
    echo '<a rel="prev" href="' . get_permalink($previd). '">previous</a>'; 
} 
if (!empty($nextid)) { 
    echo '<a rel="next" href="' . get_permalink($nextid). '">next</a>'; 
} ;?> 

オリジナルのコードが書かれています:

// get_posts in same custom taxonomy 
$postlist_args = array(
    'posts_per_page' => -1, 
    'orderby'   => 'menu_order title', 
    'order'   => 'ASC', 
    'post_type'  => 'your_custom_post_type', 
    'your_custom_taxonomy' => 'your_custom_taxonomy_term' 
); 
$postlist = get_posts($postlist_args); 

// get ids of posts retrieved from get_posts 
$ids = array(); 
foreach ($postlist as $thepost) { 
    $ids[] = $thepost->ID; 
} 

// get and echo previous and next post in the same taxonomy   
$thisindex = array_search($post->ID, $ids); 
$previd = $ids[$thisindex-1]; 
$nextid = $ids[$thisindex+1]; 
if (!empty($previd)) { 
    echo '<a rel="prev" href="' . get_permalink($previd). '">previous</a>'; 
} 
if (!empty($nextid)) { 
    echo '<a rel="next" href="' . get_permalink($nextid). '">next</a>'; 
} 

your_custom_taxonomy_term何ですが?私は自分の分類法のために持っているとは思わないので?

通常のナビゲーションは動作しません:

<?php posts_nav_link('separator','prelabel','nextlabel'); ?> 

は似たものを作ったりどこから始めれば知っている誰もが

答えて

0

使用...この

<?php previous_post_link('<div class="prev">%link</div>'); ?> <?php next_post_link('<div class="next">%link</div>'); ?>

あります%linkは次のチームメンバーの名前を表示します

+0

ありがとうございます。しかし、それはカスタムタクソノミーでは機能しません。それはちょうど次の投稿に行き、カスタムタクソノミーをファイリングしません。 – Steggie

0

知りたいことがあれば、私のOPの更新を見てください。

関連する問題