如何显示所有类别子菜单的帖子
问题描述:
我需要在我自己的主题中显示子菜单/类别的所有帖子。子菜单是一个类别。我的菜单看起来像这样:如何显示所有类别子菜单的帖子
- 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
答
您是否尝试过这样的事情:
<?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
你需要知道如何展示你的在页面中发布?或者您需要知道如何构建该菜单? – Mauro 2014-08-27 19:37:38
我有一个自定义菜单。子菜单(test1和test2)是一个类别。现在,我想展示例如在页面reference1上同时作为子菜单的类别的所有帖子。 – yab86 2014-08-27 19:41:14
但是你使用wp_nav_menu函数来建立你的菜单吗? – Mauro 2014-08-27 19:49:19