2014-08-27 109 views
0

我需要在我自己的主題中顯示子菜單/類別的所有帖子。子菜單是一個類別。我的菜單看起來像這樣:如何顯示所有類別子菜單的帖子

- about (page) 
- references (page) 
--reference1 (subpage) 
---test1 (submenu/category) 
--reference2 (subpage) 
---test2 (submenu/category) 

我可以使用類的ID得到所有的帖子:

<?php 
query_posts('cat=5'); 
while (have_posts()) : the_post(); 
the_content(); 
endwhile; 
?> 

但我需要類別-ID動態(的原因,爲什麼我定義該類別作爲我的自定義菜單中的子菜單)。但也許有另一種方式?!

當我在頁面reference1上,我想顯示類別test1的所有帖子。在頁面reference2上,我想顯示類別test2的所有帖子。我無法弄清楚,我怎麼能意識到這一點。任何幫助?

問候和感謝提前, Yab86

+0

你需要知道如何展示你的在頁面中發佈?或者您需要知道如何構建該菜單? – Mauro 2014-08-27 19:37:38

+0

我有一個自定義菜單。子菜單(test1和test2)是一個類別。現在,我想展示例如在頁面reference1上同時作爲子菜單的類別的所有帖子。 – yab86 2014-08-27 19:41:14

+0

但是你使用wp_nav_menu函數來建立你的菜單嗎? – Mauro 2014-08-27 19:49:19

回答

0

您是否嘗試過這樣的事情:

<?php 
$id = 5; 
$args = array('category' => $id, 'post_type' => 'post', 'order' => 'ASC', 'posts_per_page'=>-1, 'numberposts'=>-1); 
$postslist = get_posts($args); 

    foreach ($postslist as $post) : setup_postdata($post); ?> 

     <?php the_title(); ?> 
     <?php the_content(); ?> 

    <?php endforeach; ?> 

你會發現更多的信息: https://codex.wordpress.org/Template_Tags/get_posts

相關問題