• Hi there,

    I’ve added the following query_posts call to my archives.php

    <?php query_posts("gdsr_sort=rating&sort_order=desc&posts_per_page=20"); ?>

    Basically the posts have ratings (using the GD Star Rating plugin) and I’m trying to get each category displaying the highest rating posts first (and then descending down.

    The ranking is working fine BUT, my issue at the moment is that regardless of what category the user tries to navigate to, results from ALL categories show up.

    ie. If I had two categories ‘Food’ and ‘Sport’, if the user clicks on ‘Sport’, they will see the descending results for both ‘Sport’ AND ‘Food’, which obviously is incorrect.

    So my main question is, does anyone know how I can add a variable to the query_posts call so that it shows only the category selected, and not every category?

    Any help would be greatly appreciated!

    Cheers!

Viewing 1 replies (of 1 total)
  • This might shed some light:

    <?php
    if (is_category( )) {
      $cat = get_query_var('cat');
      $category = get_term_by('id',$cat, 'category');
      if ($category) {
        $args=array(
          'category__in' => array($category->term_id),
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo 'List of Posts for '.$category->name;
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
          endwhile;
        }
      wp_reset_query();  // Restore global post data stomped by the_post().
      }
    }
    ?>
Viewing 1 replies (of 1 total)

The topic ‘query_posts not showing active category’ is closed to new replies.