Forums

Categories Listing and Highlighting current category item (3 posts)

  1. gan35h
    Member
    Posted 8 months ago #

    My query is on WordPress and related to categories.

    I have a set of categories for my posts: All, Cat-a, Cat-b and Cat-c.

    a. When I click on the link to my posts page, I want to show an archive for 'All'. How do I generate a link to 'All' explicitly? Something of this kind?

    <a href="<?php bloginfo('url'); ?>">All Posts</a>

    b. I would also be displaying the list of categories (shown below). I would however need to highlight the current category (by default, All).

    <ul>
      <?php wp_list_categories('title_li='); ?>
    </ul>

    c. Also I would need all categories to be displayed whether they have posts in them or not.

    Any help on this is greatly appreciated. Thanks!

  2. tigtog
    Member
    Posted 8 months ago #

    Have you looked through these pages on the Codex already? The answer should be in there somewhere.

    Template Tags/wp list categories
    Displays a list of Categories as links. When a Category link is ...
    http://codex.wordpress.org/Template_Tags/wp_list_categories

    Function Reference/get categories
    This example will list in alphabetic order, all categories presented as links to the corresponding category ...
    http://codex.wordpress.org/Function_Reference/get_categories

    Function Reference/list cats
    Sets the list to not list all the Categories (based upon further parameters), sorts by ID in ...
    http://codex.wordpress.org/Function_Reference/list_cats

  3. gan35h
    Member
    Posted 8 months ago #

    Hi tigtog,
    Thanks for your reply!

    What I have done to get part of the intended result was this:

    <ul>
      <?php wp_list_categories('show_option_all=All&hide_empty=0&title_li='); ?>
    </ul>

    The problem still remains of the current category class activation in CSS. The current_category argument only explicitly adds the category ID.

    I am unable to frame a condition that: if the page loaded is the archive of a particular category, then current-cat CSS class for that category should be activated.

    Any tips? Thanks!

Reply

You must log in to post.

About this Topic