• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Page vs Category Navigation CSS

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Page vs Category Navigation CSS

This topic is: resolved

Tagged: category template, css, navigation, page template

  • This topic has 3 replies, 1 voice, and was last updated 10 years, 4 months ago by Gina.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • February 22, 2015 at 3:36 pm #141802
    Gina
    Member

    I created a template for pages that I need specific css styling for navigation. However, I'm not sure how to create a template for the same purpose for category posts and archives.

    This is what I'm trying to do...
    The main website has this gold navigation: http://plaqueminesparish.com/wp/
    Then the homeland security section has a blue nav and secondary nav and different stuff in the sidebar: http://plaqueminesparish.com/wp/homeland-security-emergency-preparedness/

    I've got everything handled EXCEPT for category archive pages in the homeland security section. Well I was able to style one category archive but not able to style others. This one has it http://plaqueminesparish.com/wp/category/homeland-security/hsep-in-depth/ but this one I haven't been able to get the styles to work http://plaqueminesparish.com/wp/category/homeland-security/parish-plan/

    I thought I would make all of the posts in the whole homeland security section have the same parent category and then just style that, however I cannot figure out how to make the parent category part of the body class. I have this in my child theme functions php but it's not working:

    /* Add category and parent to body class */
    function pn_body_class_add_categories( $classes ) {

    // Only proceed if we're on a single post page
    if ( !is_single() )
    return $classes;

    // Get the categories that are assigned to this post
    $post_categories = get_the_category();

    // Loop over each category in the $categories array
    foreach( $post_categories as $current_category ) {

    // Add the current category's slug to the $body_classes array
    $classes[] = 'category-' . $current_category->slug;

    }

    // Finally, return the $body_classes array
    return $classes;
    }
    add_filter( 'body_class', 'pn_body_class_add_categories' );

    function add_parent_category_body( $classes )
    {
    global $post;

    $categories = get_the_category( $post->ID );
    $classes[] = $categories[0]->slug;

    return $classes;
    }
    add_filter( 'body_class', 'add_parent_category_body' );

    I just need the following archives to be styled like the rest of the homeland security section:
    http://plaqueminesparish.com/wp/category/homeland-security/parish-plan/
    http://plaqueminesparish.com/wp/category/homeland-security/residential-emergency-planning/
    http://plaqueminesparish.com/wp/category/homeland-security/business-emergency-planning/
    http://plaqueminesparish.com/wp/category/homeland-security/evacuation-guidelines/

    Any ideas on how to handle this would be very much appreciated!!!! Thanks in advance.

    February 22, 2015 at 4:12 pm #141807
    Gina
    Member

    I found this which will enable me to add a custom body class to a category slug but I can only do it with one category and I wasn't able to add it to the parent category homeland-security.

    ## add a custom body class
    add_action( 'body_class', 'ilwp_add_my_bodyclass');
    function ilwp_add_my_bodyclass( $classes ) {
    if ( is_category( 'custom-category' ))
    $classes[] = 'my-custom-class';
    return $classes;
    }

    February 23, 2015 at 8:42 am #141863
    Gina
    Member

    Did I provide too much information? LOL Or is there no good answer to this?

    February 23, 2015 at 11:53 am #141889
    Gina
    Member

    For what it's worth, this ended up resolving my issue:

    /* add a custom body class */
    add_action( ‘body_class’, ‘ilwp_add_my_bodyclass’);
    function ilwp_add_my_bodyclass( $classes ) {
    if ( is_category( array(parish-plan,residential-emergency-planning,business-emergency-planning,evacuation-guidelines) ) ) { echo ‘hi'; }
    $classes[] = ‘hsep';
    return $classes;
    }

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble