Grow your CSS skills. Land your dream job.

Current Navigational Highlighting

  • # March 8, 2013 at 1:18 pm

    I did it. Now, the highlighting works for both “Home” and “Blog” because they are receiving the proper body class. How do I accomplish this with a static page on “Home” and moving my posts to “Blog?” Does this require extra PHP?

    # March 8, 2013 at 3:38 pm

    The body_class should return classes that belong to specific page/post regardless if you have latest posts or static page selected.

    Something is not working or you have configured settings/templates incorrectly.

    I’ve tested with clean install of WordPress along with blank themes from [HTML5 Reset](https://github.com/murtaugh/HTML5-Reset-Wordpress-Theme) and [Bones](https://github.com/eddiemachado/bones).

    You can try using [conditional statement](http://codex.wordpress.org/Function_Reference/is_front_page) `is_front_page()` to check if user is on Front Page then just output corresponding classed to the body. But this should not be necessary, `body_class()` should take care of this…

    # March 8, 2013 at 7:38 pm

    I am using Starkers. I wonder if this is a known error for it or if I did something I should not have. Hrm.

    # March 8, 2013 at 8:12 pm

    Just tested Starkers out of the box and it works both as static page and latest posts

    # March 8, 2013 at 8:26 pm

    Alrighty then. Ugh. I guess it is time for me to figure out what I did to it to make it not work. Thank you, @AlenAbdula.

    # March 8, 2013 at 8:39 pm

    I just installed a fresh version of Starkers, only copying over the style.css and header.php. In Starkers, they differentiate between header.php and html-header.php. So, the only things I copied over were styles and the menu basically. And it is still not giving me a body class for Blog. You can see here for yourself. So, I do not know what is causing it.

    Edit #1: I just removed style.css and it is still not giving me a body class. So it has to be something in the header.php. Hrm. Let me remove that and see if it does anything.

    Edit #2: Nope. It still does not have a body class even if I replace header.php. Suggestions? Do I need to reinstall WordPress in its entirety?

    # March 8, 2013 at 8:54 pm

    Wait, wait… the `body_class()` is a WordPress function. It has nothing to do with CSS file. It simply outputs page, post, environment details to `body` html element so that you can target them in your style sheet. These “classes” are predefined by WordPress.

    You could add custom classes, like so:

    >

    # March 8, 2013 at 9:00 pm

    But something is keeping it from producing a body_class() for Blog, correct? So, how do I go about figuring this out? Sorry, that escalated quickly. I just hate to think something is fundamentally wrong with code that I had no hand in to begin with.

    # March 8, 2013 at 9:16 pm

    How is your theme structured? Are you using any custom templates for your blog? Are you altering something via filters/hooks in your functions.php file?

    # March 8, 2013 at 9:20 pm

    It is a basic Starkers theme with no custom templates. And I do not know what filters/hooks are, so I doubt that would be the case. I have only added one PHP function to functions.php, which I promptly commented out when this whole situation started.

    # March 8, 2013 at 9:32 pm

    Ok lets do this:

    1. Deactivate all of your plug-ins (reload the page, see if it works)
    2. Then turn on plug-ins one-by-one, going back and refreshing after each activation to see if it works. This could be plug-in issue…

    # March 8, 2013 at 9:43 pm

    All plug-ins have been deactivated (there was only one active plug-in: bbPress) and there is still no body class on /blog/.

    # March 8, 2013 at 10:07 pm

    How about, re-uploading the `wp-admin` and `wp-includes` folders from a fresh download of WordPress…

    Remember to back up before! Just in case.

    # March 8, 2013 at 10:09 pm

    This might help too: http://wpshout.com/body_class/

    # March 8, 2013 at 10:44 pm

    Okay, I replaced the wp-admin and wp-includes, no luck thus far. I will read the article now.

    Edit: I read the article. In order for me to use that article’s method, I would first need a body class, which I do not have. I find it very strange that every page is producing an unique body class except for /blog/, simply because I am using a static page for home. This is very frustrating.

Viewing 15 posts - 16 through 30 (of 43 total)

You must be logged in to reply to this topic.

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