Support » Themes and Templates » if page has subpages … else …

  • I want to display a page’s subpages if it has any, and if there are no subpages, i want to display some text.

    Im trying this code but can not get it to work, it keeps displaying the “text if else” even if there ARE subpages. Help?

    global $id;
    $vm = wp_list_pages("title_li=&child_of=$id&show_date=modified&date_format=$date_format");
    if ($vm) {$vm;}
    else { echo 'text if else'; };
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer



    try it with this:

    	global $post;
    	$vm = wp_list_pages("title_li=&child_of=$post->ID&echo=0&show_date=modified&date_format=$date_format");
    	if ($vm != '') {
    		echo '<ul>' . $vm . '</ul>';
    	} else {
    		echo '<p>text if else</p>';



    Forum Moderator

    general idea:

    read the codex pages for a given function if you encounter problems:

    in this case:

    i.e. the use of the ‘echo’ parameter if you want to use the function output in a conditional statement.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘if page has subpages … else …’ is closed to new replies.