开发者

Lists wordpress posts by category and tag

I would like to generate all posts that has say a category name of X and a tag 开发者_C百科name of Y with in wordpress.

 query_posts('cat=X List&tag=Y');

I above works to an extent but not fully since I need to repeat this list and just echo the_title(). The problem is very similar to the one found here, the solutions provided there would be ideal but none work. Any help would be appreciated, thanks in advance!


$my_query = new WP_Query('category_name=cool&tag=hot');
while ($my_query->have_posts()) : $my_query->the_post();
    the_title();
endwhile;


There are also some plugins out there that should be able to do the trick for you. 'List Category Posts' allows you to just drop in one line of code into the page or post you want listing your category of posts. It allows for multiple variables to be passed through to customize the output, so I would assume it would be easy enough to filter by tags as well as the category. May save you a little time and allow for only particular pages to display categories if you have a variety of types of pages.


                <?php 
                $the_query = new WP_Query('tag_id=15&showposts=5'); 
                while ($the_query->have_posts()) : $the_query->the_post();?>

I'm just wondering why the 'tag_id=15' doesn't work in this case.... neither when I'm using 'tag=word1+word2'

Appreciate if anyone could shed some light...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜