• I am using the following styling to pull in a custom banner for my pages. This works well for the top page and the child page. However, I’ve added a grandchild page. How would I modify the CSS to style the banner for the grandchild?

    .page-id-9 #banner, .parent-pageid-9 #banner  {
    	background: #15375e url('images/broadband.png') no-repeat left;
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    It would depend on what pages you want the style applied to. View the HTML source of the grandchild page. Examine the body classes assigned and pick one that you think will work. .page-id-?? will only apply to that page. .parent-pageid-?? will apply to all children of that parent.

    You will see there is no grand parent class, only page id and parent id classes are available for specific id designations, the other classes are generic. If need be, it is possible to add in custom classes using the ‘body_class’ filter.

    https://codex.www.ads-software.com/Function_Reference/body_class#Add_Classes_By_Filters

    example:

    add_filter('body_class','grandparentpageclass');
    function grandparentpageclass($classes) {
    	if( is_page() ) {
    		global $post;
    		$ancestors = get_ancestors( $post->ID, 'page' );
    		if( count( $ancestors ) >= 2 ) $classes[] = 'grandparent-pageid-'.$ancestors[1];
    	}
    	return $classes;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘CSS Styling Based on Grandparent Page? How to?’ is closed to new replies.