2013-04-30 88 views
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,但沒有成功。

  • 有人可以給我一個提示如何進行?

回答

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> 
+0

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

+0

編輯了這個例子 – diggy 2013-04-30 14:53:58

相關問題