开发者

getting posts from multiple categories in blog category template

I have 5 blog sections each representing a category. However, I 开发者_如何转开发would like to have a category called "all" that if checked would include the post in all 5 section without having to click every category.

I guess the only way to do this is to add something into the blog category template file to tell it to include the usual category posts as well as the "all" category.

now I think i've located where it queries the post: if ( $wp_query->have_posts()) : while (have_posts()) : the_post();

but there is nothing identifying the current category id, except for a few things above for specifying the right title for the theme.

What would be the best way of achieving what I have explained?


You can interact with the wp_query object... the same way that you interact with query_posts()... it accepts the same arguments.

For either you can use Category Parameters as follows (from the wordpress codex: query_posts function reference)

Category Parameters Show posts associated with certain categories.

  • cat (int) - use category id.

  • category_name (string) - use category slug (NOT name).

  • category__and (array) - use category id.

  • category__in (array) - use category id.

  • category__not_in (array) - use category id.

When it references $wp_query, the variables of the query have already been defined, you can set up your own query with any parameteres you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜