0

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
  • Do you have an explicit category named "All", or do you just mean "all posts"?
    – Jan Fabry
    Commented Sep 12, 2011 at 5:52
  • I do have an explicit category called 'All', however that can be altered in the argument list in the wp_list_category() codex. When viewing a page of posts, I wanted the 'All' category highlighted, that's why I wanted to link to the dynamic link to the 'All' page. Please let me know if you need more information. Thanks!
    – Ganesh
    Commented Sep 13, 2011 at 2:48

1 Answer 1

1

On the Codex page for wp_list_categories(), you can see the two following arguments that might help you:

  • hide_empty: Toggles the display of categories with no posts. The default is true (hide empty categories).
  • current_category: Allows you to force the current-cat CSS class to appear on uses of wp_list_categories() that are not on category archive pages.

Note that current_category only accepts one category ID. If you have a post that belongs to two categories, you will have to choose one.

2
  • Many thanks for your answer Jan! Greatly appreciated! Apologies for my delayed response, however, as I have one more query. Where do I specify which category to choose?
    – Ganesh
    Commented Sep 13, 2011 at 2:54
  • Ok, so the current_category is where I explicitly put in the ID of the category. However, that doesn't seem to activate the current-cat class in CSS. Also what I have done to get part of the intended result was this: <?php wp_list_categories('show_option_all=All&hide_empty=0&title_li='); ?> 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!
    – Ganesh
    Commented Sep 13, 2011 at 3:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.