WordPress.org

Ready to get started?Download WordPress

Forums

Looking for plugin: Show latest categories (7 posts)

  1. Jorge05r
    Member
    Posted 5 years ago #

    I'm looking for a plugin which it will show the latest categories created, anyone knows something similar?

    THank you

  2. Dagon Design
    Member
    Posted 5 years ago #

    I'll write some code for it

  3. Dagon Design
    Member
    Posted 5 years ago #

    Here you go. It is just some code for now, you can stick it in your theme files somewhere. I will probably turn it into a plugin as well soon.

    Since categories do not really have a creation date, it sorts by their ID, which has the same effect. Just set $num_cats to choose how many to display, and you can customize the output generation - it is currently just displaying a list.

    <?php
    
    global $wpdb;
    $tp = $wpdb->prefix;
    
    $num_cats = 5;
    
    $cats = (array)$wpdb->get_results("
    	SELECT {$tp}terms.term_id as id, {$tp}terms.name as name
    	FROM {$tp}terms, {$tp}term_taxonomy
    	WHERE {$tp}terms.term_id = {$tp}term_taxonomy.term_id
    	AND {$tp}term_taxonomy.taxonomy = 'category'
    	ORDER BY {$tp}terms.term_id DESC
    	LIMIT $num_cats
    "); 
    
    if (count($cats > 0)) {
    	echo '<p>Last ' . $num_cats . ' categories created:</p>';
    	echo '<ul>';
    	foreach ($cats as $c) {
    		echo '<li><a href="' . get_category_link($c->id) . '">' . htmlspecialchars($c->name) . '</a></li>';
    	}
    	echo '</ul>';
    }
    
    ?>
  4. Jorge05r
    Member
    Posted 5 years ago #

    Thanks Dagon Design, I will try it and see if it works :)

    Appreciate your help!

  5. Dagon Design
    Member
    Posted 5 years ago #

    Let me know how it goes :)

  6. Dagon Design
    Member
    Posted 5 years ago #

  7. Jorge05r
    Member
    Posted 5 years ago #

    Thanks Dagon Design, the code was fine. It worked just the way I wanted it.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.