Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#4821 closed defect (bug) (invalid)

wp_list_categories() messes up the current category

Reported by: xtc62 Owned by:
Milestone: Priority: low
Severity: trivial Version: 2.2.2
Component: General Keywords:
Focuses: Cc:


I tried on my blog to list the latest 5 posts from some of my categories so I used a "second loop" like this:

<?php query_posts('cat=5&showposts=5');

and then the usual loop routine with

<?php while( have_posts() ) : the_post(); ?>
<?php endwhile; ?>

After this I wanted to list all of my categories using the wp_list_categories() but found out that even if I was under category with ID=6(for example) the category with ID=5 was still the one classed with "current-cat". I'm shure it has to do something with that "second loop" thing since the category that is being marked as current is the last for which I've called the loop for and if I call the wp_list_categories() before the second loops it works all right.

I'm not sure if this is a bug or a feature but if it's the former this I think would be the best place to start fixing it:

//wp-includes/category-template.php around line 245
if ( is_category() )
     $r['current_category'] = $wp_query->get_queried_object_id(); 

The logic in Walker_Category::start_el() seems correct.

Change History (4)

comment:1 foolswisdom7 years ago

xtc62, please test and report bugs verses the current version, which is currently 2.2.2 , even better there will be a 2.3 beta this week. Thank you.

comment:2 xtc627 years ago

  • Version changed from 2.1.3 to 2.2.2

I noticed while posting that I don't have the latest version so I upgraded but I forgot to change the "version" field to 2.2.2. Anyway, the bug is present in version 2.2.2 too( again, if indeed it's a bug ).

comment:3 ryan7 years ago

  • Resolution set to invalid
  • Status changed from new to closed

You have to restore the original query.

$GLOBALS['wp_query'] =& $GLOBALS['wp_the_query'];

In 2.3 you can use wp_reset_query().

comment:4 foolswisdom7 years ago

  • Milestone 2.4 (next) deleted
Note: See TracTickets for help on using tickets.