Leveraging AI to Supercharge Your WordPress Business Website
In today’s competitive digital landscape, every business website needs an edge to...
5.Jul.2015 | Code Snippets, Freelance Web Design, Wordpress
Add this to your functions.php to add a class to all pages within a tree:
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath
global $post; // load details about this page
$cpid = get_the_ID();
$parents = get_post_ancestors( $post->ID ); // get the ancestors
$ancestorid = ($parents) ? $parents[count($parents)-1]: $post->ID;
if(($post->post_parent==$pid||$cpid==$pid||$ancestorid==$pid))
return true; // we're at the page or at a sub page
else
return false; // we're elsewhere
};
// Then use this conditional anywhere in your template files:
if ( is_tree( //page id here ) ) :
// Do something...
endif; ?>Reference – css tricks blog post
Wordpress Function, WordPress Tips
Share

In today’s competitive digital landscape, every business website needs an edge to...

WordPress has come a long way since its humble beginnings in 2003....

In the ever-evolving landscape of website development, staying ahead of the curve...
Handy bit of code you can use in your custom templates that grabs the all the page or post data by ID:...
Commonly asked eCommerce questions: A nice little bit of information about #PCIDSS for @WooCommerce - http://goo.gl/BSK6Ba Lee Harris - Twitter...
Need a bespoke WooCommerce site with dynamic content for two types of visitor? For example, this is from a recent...