Looking to dynamically add a body class to each page. The titles of static page’s (without children) or the parent’s page title of child pages.
That was hard to spit out!
Like this. . .
Home -> class=“home”
Projects -> class=“projects”
- Project -> class=“projects-child”
Blog -> class=“blog”
- Articles -> class=“blog-child”
About -> class=“about”
I hope that makes sense.
For the children, I’ve been able to echo the parent’s title as the class name with this code:
<body class="<?php echo $page->parent()->title()->html() ?>">
. . . in my headers.php snippet.
But the parent pages, or pages without any children, echo my site title as the body class.
And my original intention was to build this as a controller. Not sure if that’s the right approach? Maybe snippet?
Thanks for a point in the right direction.