Community Forums › Forums › Archived Forums › Design Tips and Tricks › Page vs Category Navigation CSS
Tagged: category template, css, navigation, page template
- This topic has 3 replies, 1 voice, and was last updated 9 years, 7 months ago by Gina.
-
AuthorPosts
-
February 22, 2015 at 3:36 pm #141802GinaMember
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 #141807GinaMemberI 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 #141863GinaMemberDid I provide too much information? LOL Or is there no good answer to this?
February 23, 2015 at 11:53 am #141889GinaMemberFor 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;
} -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.