按分类术语显示自定义文章类型列表

按分类术语显示自定义文章类型列表

问题描述:

我需要显示按术语分类的自定义文章类型列表。我们的想法是这样的:按分类术语显示自定义文章类型列表

服务列表:

<ul> 
<li> 
    <a href="#">Webdesign (taxonomy term)</a> 
    <ul> 
    <li>Business Website A (custom post type from this taxonomy term)</li> 
    <li>Business Website B (custom post type from this taxonomy term)</li> 
    <li>Business Website C (custom post type from this taxonomy term)</li> 
    </ul> 
</li> 
<li> 
    <a href="#">Illustration (taxonomy term)</a> 
    <ul> 
    <li>Business Illustration A (custom post type from this taxonomy term)</li> 
    <li>Business Illustration B (custom post type from this taxonomy term)</li> 
    <li>Business Illustration C (custom post type from this taxonomy term)</li> 
    </ul> 
</li> 
<li>Other service without taxonomy (if has no taxonomy, show in first level)</li> 
</ul> 

我已经试过wp_list_pageswp_list_categories,但没有成功。

  • 有人可以给我一个提示如何进行?

您可以使用get_postsWP_Query与分类参数:

http://codex.wordpress.org/Template_Tags/get_posts#Taxonomy_Parameters http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

例与get_posts

<ul> 
    <li> 
     <a href="#">Webdesign</a> 
     <ul> 
<?php $items = get_posts(array(
    'post_type' => 'my_post_type', 
    'tax_query' => array(
     array(
      'taxonomy' => 'my_taxonomy', 
      'field' => 'slug', 
      'terms' => 'webdesign' 
     ) 
    ) 
)); 
if($items){ 
    foreach ($items as $item){ 
     setup_postdata($item); 
     echo '<li>' . get_the_title($item->ID) . '</li>'; 
    } 
} ?> 
     </ul> 
    </li> 
</ul> 
+0

我需要怎么做一些更多的信息。你可以帮帮我吗? – Brightweb 2013-04-30 14:31:59

+0

编辑了这个例子 – diggy 2013-04-30 14:53:58