0815

Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Test for Sub-Pages

Until WordPress includes an is_subpage() function, here is a manual method of testing for sub-pages:

<?php global $post;

if ( is_page() && $post->post_parent ) {

    // subpage content goes here

} else {

    // non-subpage content goes here

} ?>

Further, here are some other ways to use this method to test for different combinations of pages and sub-pages:

<?php if (is_page('about') || $post->post_parent == '1') {

	$banner = 'business.png';

} elseif (is_page('archives') || $post->post_parent == '2') {	

	$banner = 'pleasure.png';

} elseif (is_page('contact') || $post->post_parent == '3') {

	$banner = 'personal.png';

} else { 

	$banner = 'default.png';

} ?>

Note that the numbers “1”, “2”, and “3” represent the IDs of the target parent pages.




0