WORDPRESS:在一个主要类别中显示子类别列表及其包含的帖子 [英] WORDPRESS: Display list of Sub-Categories and the posts they contain, within one main Category
问题描述
我找到了大量代码和插件来做各种事情;来自特定猫的展示帖子,猫的子猫等.但是,我一生都找不到,也不太了解 WP API 以完成我需要的工作..
I've found tons of code and plugins to do various things; from show posts for specific cats, subcats of a cat, etc.. BUT, I cannot for the life of me find, nor do I know the WP API well enough to do what I need with it..
这是我想要完成的:
显示 Cat31 中所有子猫的 UL,以及每个子猫的帖子:
Display a UL of all subcats within Cat31, and the posts for each of those subcats:
SubCat1发布 1帖子 2
SubCat1 Post 1 Post 2
SubCat2发布 1帖子 2
SubCat2 Post 1 Post 2
SubCat3发布 1帖子 2
SubCat3 Post 1 Post 2
这很简单,但是我尝试过的所有循环都在 subcat 循环或 post 循环中失败(一个或另一个有效,我无法让它们都工作..)
It's pretty straight forward, but all the loops I have tried fail either at the subcat loop or the post loop (one or the other works, I cannot get them both to work..)
所以,除非我能找到一个插件来做到这一点(我更愿意将其编码到模板文件中!)然后我需要弄清楚如何:
So, unless I can find a plugin to do this (I'd prefer to code this into a template file!) then I need to figure out how to:
Cat31 中的循环子猫在循环 subcasts 时,为每个 subcat 循环帖子
Loop Subcats within Cat31 while looping subcasts, loop posts for each subcat
非常感谢任何帮助!
推荐答案
我认为这就是您所需要的.
I think here's what you need.
$categories= get_categories('child_of=10'); for each $categories as $category {
//Display the sub category information using $category values like $category->cat_name
$posts_array = get_posts( 'category=$category->cat_ID' );
for each $posts_array as $post {
//Display the posts information using $post values like $post->post_title
} }
你只需要格式化它们.希望这会有所帮助.
You just need to format them. Hope this would be of help.
这篇关于WORDPRESS:在一个主要类别中显示子类别列表及其包含的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!