0

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

服务清单:

<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,但没有成功。

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

1 回答 1

1

您可以使用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>
于 2013-04-30T13:17:19.137 回答