WordPress.org

Ready to get started?Download WordPress

Forums

Get category slug on category archive page. (2 posts)

  1. keriati
    Member
    Posted 3 years ago #

    Hello!

    How can i get the current category slug (and category id too) on the category archive page?

    I need it to make some lists of popular posts on the category page too.

    ~

  2. Cliff Seal
    Member
    Posted 3 years ago #

    <?php
    $cat = get_category( get_query_var( 'cat' ) );
    $cat_id = $cat->cat_ID;
    $cat_name = $cat->name;
    $cat_slug = $cat->slug;
    ?>

    Hat Tip for that code.

    That gets you your first request. On the second, if you're looking to order posts by comment count, use query_posts and the orderby parameter.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags