• Hi All

    I have a blog where each post is in 2 different categories, and want to highlight BOTH of them at the same time when on that specific post within the sidebar.
    I’m displaying the categories as 2 different menus (by using the ‘my custom widget’ plugin and excluding one set of categories for each list). So far, I have only been able to highlight one category at a time by using the current-cat in the css. Is it possible to assign a new class (or the same class!) to the other category?
    Any help would be greatly appreciated!

    Thanks

    C

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter coche09

    (@coche09)

    Any ideas anyone?

    I’ve been using this code below, i feel like im getting closer but still can’t figure it out.
    how can I assign a new class called current to another category to which the post also belongs to in order to highlight it?

    any help is greatly appreciated!

    <?php if (is_category ('cat1')){echo ' class="current"'; } –> this only echoes the text “class=current”.

    `<?php if (is_category (‘cat1’)){echo ‘class= “current”‘ ;
    wp_list_categories (‘include=4&title=’);} ?>` –> not assigning the class, just echoing the text but showing the category i need.

    `<?php if (is_category (‘cat1’)){
    echo ‘class= “current”‘ ; } ?>
    “> <?php wp_list_categories (‘include=4&title=’);?>` –> this duplicates the categories and the class is empty!

    thanks!

    c

    the conditional template tag in_category('cat1') might be a better choice to use;
    http://codex.wordpress.org/Function_Reference/in_category

    a link to your site might also illustrate your setup.

    and you could paste the full code of your category listing (‘my custom widget’ ?) in a http://wordpress.pastebin.com/ , and someone might have a look at it and might be able to comment on it.

    Thread Starter coche09

    (@coche09)

    Thanks alchymyth for the response.

    I will take a look at it with the in_category tag.

    a link to the site:
    http://www.petebarry.com/portfolio (right now im testing something with the categories and the post title)

    the ‘custom widget plugin’ shouldn’t really be interfering, it’s a plugin that allows you to write php/html and creates a widget (http://wordpress.org/extend/plugins/mycustomwidget/). All I’m doing with it is creating 2 category lists including different cats:

    widget 1
    wp_list_categories ('include=1,2,3,4,5&title=');
    widget 2
    wp_list_categories ('include=5,6,7,8,5&title=');

    I guess the main thing i need to figure out is how to add a custom class to another item from the categories list OR to the current post title

    Alternatively, if having two categories highlighted is too tricky, it could be done by adding the custom class to a page ( i can put the content in a page instead of a post) or as mentioned before, to the post title. the key is to be able to have them highlighted at the SAME TIME .

    Thanks
    c

    ‘wp_list_category()’ only ‘highlights’ the category if it is on the category page; therefore there will be never two categories highlighted at the same time.

    if you want to have a category list in a post (in the sidebar) which ‘highlights’ all the post’s categories (when you are in single.php), you need to look for a function with code that can do this.
    (plugins for a category widget with this functionality are available; so how to do it is known.)

    i haven’t seen anything just as a function, so the following code, added to functions.php of the theme, is supposed to do this;

    http://wordpress.pastebin.com/p3pGMXkg

    ‘hi_list_categories();’ is intended to be used with the same range of arguments as the standard ‘wp_list_categories();’ –
    (i.e. the ‘include’ parameter should work)

    in single post view, it adds the class .current-cat to the list element of the categories of the post.
    otherwise it will output a list in the same way as ‘wp_list_categories();’

    Thread Starter coche09

    (@coche09)

    Hey Alchy
    Thanks a bunch for your help. I’ll take a look at the code you posted in there.

    Really really appreciate it!

    Thanks again

    C

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Highlight Multiple Categories in Sidebar?’ is closed to new replies.