Support » Themes and Templates » the_category acting strangely with query_posts

  • Resolved WTFranklin


    I have been setting up a theme based on one I made in the past. I’ve been having trouble with using the the_category() function. It gives the name of the category the post just fine, but when I click on it it doesn’t bring up posts filtered by the category name. I have disabled the plugins that were activated, but that didn’t change anything. I have been attempting to query the 5 recent posts, which when I comment that out it seems to fix the trouble with the_category() function. I’ve tried a couple ways of querying the recent 5 posts:


    The other way I’ve tried is using this before the loop:

    $temp = $wp_query;
     $wp_query = null;
     $wp_query = new WP_Query();
     $wp_query->query('showposts=5' . '&paged=' . $paged);

    then after the loop I have

    $wp_query = null;
    $wp_query = $temp;

    to fix what that changed before. I didn’t have this issue before while querying a specific amount of posts in the past and I’m not sure which is the best to still be able to get the most recent posts and still have the_category() function still work the same. Just seeing if anyone can give me some insight to what I might have done in correctly.



Viewing 1 replies (of 1 total)
  • Actually, I figured it out with some more google searching and meddling. If I use the query_posts function I have to add in the variable $query_string and an ampersand for the query variable like this:

    query_posts($query_string . '&posts_per_page=5');

    hopefully that helps someone!


Viewing 1 replies (of 1 total)
  • The topic ‘the_category acting strangely with query_posts’ is closed to new replies.