How to sort posts in category.php without using query_posts in WordPress

It seems, that standard WP loop works smoothly, when I need to categorize posts. When used in category.php it displays only posts added to a certain category, for example: I have two categories, movies and music, and i have posts assigned to each of the cetgory, and also I have posts assigned to both of the categories. If so, posts assigned to both of the categories are displayed in both categories perfectly, while posts assigned to one category are displayed only on one category page. I tried to sort them by date or id, but using query_posts doesn’t work. It causes to display all posts on all category pages apart form they’re groupped by certain category. Is there a way to sort them in different way?

edit:

Read More

it’s the standard loop, where everything works perfectly. as I written above, while having ‘movies’ category page, posts assigned only to ‘movies’ category are displayed on that page, and it’s like that with every category page. But it’s sorted, I think, by date and descending.

<div class="category_info"><?php echo category_description(); ?></div>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="categorymain">
<h4 class="posttitle"><?php the_title(); ?></h4>
<?php echo intro_text(250); ?>
<a href="<?php the_permalink() ?>" class="readmore">read more ร‚ยป</a>
</div><!--end categorymain-->
<?php endwhile; endif; ?>

but, when I wrap everything with

<?php query_posts('order=ASC'); ?>
//...above code here
<?php wp_reset_query();?>

everything is ruined. On ‘movies’ category page posts form ‘movies’ category are displayed, but also posts from every other category, not related to ‘movies’, and this happens on every category page. I hope I made it clear ๐Ÿ™‚ Oh, and by the way, everything is coded in category.php.
greets to everyone:)


edit

I foud a seamless solution, here it is:

<?php global $wp_query;
$args = array_merge( $wp_query->query, array( 'category__in' => array(get_query_var('cat')), 'order' => 'DESC', 'orderby' => 'title' ));
query_posts( $args );
?>

Related posts

Leave a Reply

2 comments