WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to order category the way I want it? (7 posts)

  1. Jellelle
    Member
    Posted 5 years ago #

    Hi guys.

    I just updated from 2.7 to 2.8, and the only problem I have, is my category list.

    It should show the last 5 active categories:
    <?php wp_list_categories('orderby=post_date&order=DESC'); ?>

    But in 2.8 I get: NO CATEGORIES in my page.

    I took a look here: (but I can't find 'orderby=post_date')

    So the question is: How can I get a list with all my categories, the ones last added a new post to, on top?

    Cheers,
    Jelle

  2. MichaelH
    Member
    Posted 5 years ago #

    Don't even know why that worked at 2.7, but the orderby can only be ID, name, slug, count, or term_group (these are actually defined by the function get_terms).

  3. Jellelle
    Member
    Posted 5 years ago #

    well, I thought it worked in 2.7. didn't had that many categories :)
    At lest they where showing up without displaying NO CATEGORIES.

    So there is no way to do this?

  4. MichaelH
    Member
    Posted 5 years ago #

    So there is no way to do this?

    -Get all your posts
    -Loop through posts newest to oldest till you've got one post for each of your five categories
    -Then display those posts

  5. Rumores
    Member
    Posted 5 years ago #

    Hi Jellelle

    You can also try "My Category Order" plugin (WP 2.8 compatible) to do what you need.

    Usage after manual category switches on admin panel :
    wp_list_categories('orderby=order&...');

    Great addon to override wordpress default way of listing categories ;)

    Cheers,
    Rumores

  6. Jellelle
    Member
    Posted 5 years ago #

    Thanks all!

  7. Jellelle
    Member
    Posted 5 years ago #

    For those who want to know, here is the code I smashed together (no coding guru!)

    <?php
    $cat_posts = new WP_Query('orderby=post_date&showposts=-1');
    $i = 0;
    
    if($cat_posts->have_posts()) :
    	while($cat_posts->have_posts()) : $cat_posts->the_post();
    
    		$category = get_the_category();
    		$allcategoriesID[$i] = $category[0]->cat_ID;
    		$i++;
    
    	endwhile;
    endif;
    
    $recentcategoriesID = array_values(array_unique($allcategoriesID));
    
    for ($counter = 0; $counter <= 1; $counter += 1) {	//Show last 2 categories who have been updated
    	$args_temp = array('include' => $recentcategoriesID[$counter],'title_li'=>'');
    	wp_list_categories($args_temp);
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic