Custom WordPress function to check page parent
— Quick update to the is_subpage() function. Basically it’s does the same but now it also accepts an integer to check if the current page is a child of certain ID. This way its easier to track if the current location is a subpage of a certain page. If it matches it will return a true value otherwise, it will be false.
function is_subpage( $iID = null )
{
global $post, $wpdb;
if ( is_page() AND isset( $post->post_parent ) != 0 )
{
$aParent = $wpdb->get_row( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d AND post_type = 'page' LIMIT 1", $post->post_parent ) );
if ( is_int( $iID ) > 0 )
if ( $aParent->ID == $iID ) return true; else return false;
else
if ( $aParent->ID ) return true; else return false;
}
else
{
return false;
}
}
/* EXAMPLE */
if ( is_page('producs') OR is_subpage( 8 ) )
{
//do something
};
Cheers!



