if page has subpages ... else ... (3 posts)

  1. egjweb
    Posted 4 years ago #

    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'; };
  2. keesiemeijer
    Posted 4 years ago #

    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>';
  3. Michael
    Forum Moderator
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic