admin管理员组文章数量:1430030
I am trying to set up a category archive (editing category.php) that displays a list of posts from one single category. If I left the twentyten default code
(get_template_part( 'loop', 'category' );)
and i go to www.mysite/categoryname it correctly filters the posts only for the categoryname.
If I try to use my custom query code, going to www.mysite/categoryname every post is displayed, despite of category. This is the loop code:
<?php if (have_posts()) : ?>
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'orderby' => comment_count,
);
query_posts($args);
while (have_posts()) : the_post();?>
MY CUSTOM CONTENT
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
thanks
I am trying to set up a category archive (editing category.php) that displays a list of posts from one single category. If I left the twentyten default code
(get_template_part( 'loop', 'category' );)
and i go to www.mysite/categoryname it correctly filters the posts only for the categoryname.
If I try to use my custom query code, going to www.mysite/categoryname every post is displayed, despite of category. This is the loop code:
<?php if (have_posts()) : ?>
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'orderby' => comment_count,
);
query_posts($args);
while (have_posts()) : the_post();?>
MY CUSTOM CONTENT
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
thanks
Share Improve this question asked May 7, 2011 at 10:33 AndycapAndycap 5852 gold badges9 silver badges22 bronze badges1 Answer
Reset to default 3That happens because you are overwriting the query with you $args, If you want to modify it and not overwrite it then use this format:
//get the $query_string in to your $args array
global $query_string;
parse_str( $query_string, $args );
//modify whatever you want
$args['post_type'] = 'post';
$args['posts_per_page'] = 5;
$args['orderby'] = 'comment_count';
query_posts($args);
本文标签: Category page showing posts from all categories
版权声明:本文标题:Category page showing posts from all categories 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745550960a2662941.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论