Grow your CSS skills. Land your dream job.

WordPress Category Selected

  • # September 18, 2009 at 4:49 pm

    I was wondering how when ever you click the video tab or freebie tab it changes and it is selected. I know how to do this in HTML but how do u do it in wordpress?

    # September 18, 2009 at 9:50 pm

    typically you would either, retrieve the page-slug and echo it as the body id, or if you want to keep it abit simpler/less specific a basic conditional statement using the likes of these functions:

    Code:
    if (is_home())
    echo ‘homepage';
    else if (is_single())
    echo ‘blogpost';
    else if (is_page_template(‘whatever.php’))
    echo ‘whatever';

    etc (full listings of these can be found http://codex.wordpress.org/Conditional_Tags )

    the idea is just to echo one of the values into the body id then use css specificity to set the ‘on’ state for each one

    Code:
    #menu li { off-state-for-all-links }

    /* Highlighted state for each link only working when the correct id is inserted into the body */
    #homepage #menu #homepagelink { css-for-on-state }
    #blogpost #menu #bloglink { css-for-on-state }
    #whatever #menu #whateverlink { css-for-on-state }

    Something along those lines, you can do it in varying ways obviously, but I hope that was a decent example.

    just for clarity im assuming html along the lines of :

    # September 18, 2009 at 11:11 pm

    k thanks. can i contact u if i need anymore help when designing the page.

    # September 18, 2009 at 11:27 pm

    so i have to have a custom page template for every category?

    # September 19, 2009 at 6:12 am
    Quote:
    so i have to have a custom page template for every category?

    not particularly !

    as long as you open your body tag in the header include you can add if () cases for almost any page type.

    Code:
    is_category()
    is_category( id )
    is_category( slug-name )

    all work :)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".