WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. egjweb
    Member
    Posted 2 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?

    <ul>
      <?php
    
    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'; };
    
    ?>
    </ul>
  2. keesiemeijer
    moderator
    Posted 2 years ago #

    try it with this:

    <?php
    	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. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    general idea:

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

    in this case:
    http://codex.wordpress.org/Function_Reference/wp_list_pages

    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