简体   繁体   English

WordPress的-使category.php也列出子类别的帖子

[英]Wordpress - Make category.php list posts from subcategories as well

I'm building a blog where three people will be writing, but they will have a separate section on the site. 我正在建立一个博客,三个人将在该博客上写作,但是他们将在网站上有一个单独的部分。 The structure is built upon categories and looks like this: 该结构基于类别构建,如下所示:

  • User one 用户一
    • Clothes 衣服
    • Fashion 时尚
    • Life 生活

  • User two 用户二
    • Family 家庭
    • Life 生活

  • User three 用户三
    • Family 家庭
    • Friends
    • Life 生活

I've set all three users as writers and used the plugin Restrict Categories in order to lock their categories to the sub-categories the matching each top level category. 我将所有三个用户都设置为作家,并使用了插件“ 限制类别” ,以便将其类别锁定到与每个顶级类别相匹配的子类别。

Now here comes the question, if I visit http://site.example/category/user-one/ I want to have a listing of all the posts, including the sub-categories since there will be no actual content in the top level category that you are browsing. 现在出现了一个问题,如果我访问http://site.example/category/user-one/我想列出所有帖子(包括子类别)的列表,因为顶层没有实际内容您正在浏览的类别。

I've tried making this using filters bound to pre_get_posts but I still can't get it to work. 我尝试使用绑定到pre_get_posts过滤器进行此操作,但仍然无法正常工作。 Does anyone else here have any ideas? 这里的其他人有什么想法吗?

I've also given some though into actually creating a multisite network for the purpose, but I then realized it will be hard to fetch posts from all the networks at once. 我还为此目的实际创建了一个多站点网络,但是后来我意识到很难一次从所有网络中获取帖子。

Thanks in advance, Jonathan 预先感谢,乔纳森

@Jonathan: Not sure if I am misinterpreting what you are hoping to achieve, but given that each author will already have their own 'author' page which lists all their posts (if your theme includes this or something you could create or customise), there may not really be a need for Users 1-3 to be their own category? @Jonathan:不确定我是否会误解您希望实现的目标,但是鉴于每个作者都已经拥有了自己的“作者”页面,其中列出了他们的所有帖子(如果您的主题包括主题或您可以创建或自定义的主题),可能真的不需要用户1-3成为自己的类别?

Going back to your question, for listing subcategories, perhaps https://wordpress.stackexchange.com/questions/13485/list-all-subcategories-from-category might be of some help. 回到您的问题,对于列出子类别,也许https://wordpress.stackexchange.com/questions/13485/list-all-subcategories-from-category可能会有所帮助。

As for listing posts, to keep things simple, I reckon you might be able to use eg get_posts ( http://codex.wordpress.org/Template_Tags/get_posts ) and build custom arguments, perhaps in a loop if you prefer to use one instead of slug/id specific category templates. 至于列出帖子,为简单起见,我认为您可能可以使用例如get_postshttp://codex.wordpress.org/Template_Tags/get_posts )并构建自定义参数,如果您更喜欢使用一个,则可以循环使用而不是slug / id特定类别模板。

http://codex.wordpress.org/Category_Templates http://codex.wordpress.org/Category_Templates

If it's any help, Bainternet actually created a plugin that makes life a little easier to define category templates: http://wordpress.org/plugins/custom-category-template/ 如果有帮助,Bainternet实际上创建了一个插件,使定义类别模板的工作变得更轻松: http ://wordpress.org/plugins/custom-category-template/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM