2016-09-26 6 views
3

アイテムを一覧表示せずにホーム画面にカスタム投稿タイプのすべてのカテゴリを表示する方法。WordPressで利用可能なすべてのカスタム投稿カテゴリを表示するには?

私は既にカスタム投稿タイプとそのカテゴリを作成しました。今では、各カテゴリページへのリンクとして私のホームページにすべてのカテゴリを表示する必要があります。誰か助けてもらえますか?あなたが使用することができます

+1

(http://wordpress.stackexchange.com/questions/14331/get-terms-by-taxonomy-and-post-type#answer-14334)[この記事の第二の答え]の表情を持っています。 –

答えて

-1
$args = array('post_type' => 'post', 'posts_per_page' => 10); 
$loop = new WP_Query($args); 
while ($loop->have_posts()) : $loop->the_post(); 
     the_title(); 
    echo '<div class="entry-content">'; 
     the_content(); 
    echo '</div>'; 
endwhile; 
+0

これは、カスタムポストタイプの項目をリストします。カスタムポストタイプの項目はリストしません。 –

1
$cat_args = array(
    'taxonomy' => 'your-custom-post', // your custom post type 
); 
$custom_terms = get_categories($cat_args); 
echo print_r($custom_terms); 
+1

これは間違っています。 taxonomy paramterは、ポストタイプを想定していません。ここをクリック - > [get_categories](https://developer.wordpress.org/reference/functions/get_categories/) –

2

get_categories

ここではコードの例です:

<?php 
    $args = array(
       'taxonomy'   => 'Your Taxonomy Name' 
       'hide_empty'  => 0, 
       'orderby'   => 'name' 
      ); 

    $cats = get_categories($args); 

    foreach($cats as $cat) { 
?> 
     <a href="<?php echo get_category_link($cat->slug); ?>"> 
      <?php echo $cat->name; ?> 
     </a> 
<?php 
    } 
?> 

は、あなたが登録してがここ'Your Taxonomy Name'

で、あなたの分類名を書き忘れないでください

product_cat,blog_catなど

希望すると、これが役立ちます。

0
<?php 
      $terms = get_terms('taxonamy_name', array(
       'orderby' => 'count', 
       'hide_empty' => 0 
      )); 
       foreach($terms as $term) 
       { 
       echo $term->name; 
       }?> 
      </ul> 
     </div> 
関連する問題