Matthew Vaccaro

Guns, God, Country, and Code
  • Index
  • Blog
  • Snippets
  • WP Check Page Children

    This snippet was used to check a WordPress page for children. If it had none, it either printed out a list of pages or the alternate content.

    <?php  
    
    		$pageID = get_the_ID();
    
    		$args = array(
    		'title_li' => __('<h1>Heading Here</h1>'),
    		'child_of' => $pageID
    		);
    
    		$children = get_pages('child_of='.$post->ID);
    
    		if( count( $children ) != 0 ) {
    			 wp_list_pages($args);
    		}else {
    			 echo 'Alternate Content!';
    		}
    
    		?>
    Go Back