WordPress.org

Forums

highlight current category (4 posts)

  1. izc99
    Member
    Posted 8 years ago #

    hi,

    i created a dynamically highlighted menu on the sidebar as described at http://codex.wordpress.org/Dynamic_Menu_Highlighting - no problem so far. next, i introduced the is_category(); function next to is_page(); and it's working fine as well (like e.g. "/wordpress/category-one")...
    until i open the categories' single posts (like e.g. "/wordpress/category-one/123"): then, the highlightning in the sidebar-menu disappears.

    any idea where i'm wrong?

    - maybe a problem with my permalink-structure? (currently: /%category%/%post_id%)
    - or is the is_category(); function not the right way to do it?
    - or maybe i have to work with category templates as described at http://codex.wordpress.org/Category_Templates ?

    hm... maybe someone has a hint for me, that would be great!

    best, chris

  2. BPartch
    Member
    Posted 8 years ago #

    Hello

    I use this for the same purpose.

    <?php
    $post = $wp_query->post;
    if ( (is_single() && in_category('1')) )
    /* single category one pages */
    { $current = 'category 1'; }
    elseif ( (is_single() && in_category('2')) )
    /* single category 2 pages */
    { $current = 'category 2'; }
    elseif ( (is_single() && in_category('3')) )
    /* single category 3 pages */
    { $current = 'category 3'; }
    ?>

  3. moshu
    Member
    Posted 8 years ago #

    "/wordpress/category-one/123"
    The above is NOT the case for "is_category". For that link only the "is_single" is true.

  4. izc99
    Member
    Posted 8 years ago #

    thanks for your help, now it works fine!
    chris

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.