• Resolved dralezero

    (@dralezero)


    I got this to show 2 levels deep of subpages of the current page. But I need to check if there is any in the result before displaying. I have other things that get displayed that I dont want to show next to the list if there isn’t any pages in the list. Will I just have to write my own query to get a count and echo nesting loop? I like the nesting of the list items.

    <ul id="nav-subpages" role="navigation">
    		<?php wp_list_pages('child_of='.$post->ID.'&title_li=&depth=2'); ?>
    		</ul>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Try:

    <?php $my_pages = wp_list_pages('child_of='.$post->ID.'&title_li=&depth=2&echo=0');
    if( $my_pages ) : ?>
    <ul id="nav-subpages" role="navigation">
    <?php wp_list_pages('child_of='.$post->ID.'&title_li=&depth=2'); ?>
    </ul>
    <?php endif;?>
    Thread Starter dralezero

    (@dralezero)

    That worked. I’m having issue trying to get the before_widget before_title stuff to echo. When wp_list_pages is uncommented the before and after widget, title stuff doesn’t echo, but the $subpages and everything else does. My if($subpages!="") works but is commented for testing this issue now.
    It worked fine when wp_list_pages had echo=1 within the widget.

    EDIT: I fixed it. I had 'echo=0' instead of '&echo=0'

    function widget($args, $instance) {
    	extract($args);
    	$title = esc_attr(strip_tags($instance['title']));
    	$depth = intval($instance['depth']);
    
    	global $post;
    	$tmp_post = $post;
    	//$subpages = wp_list_pages('child_of='.$post->ID.'&title_li=&depth='.$instance['depth'].'echo=0');
    
    	//if($subpages!=""){
    
    		echo $before_widget.$before_title;
    
    		if($instance['title'] == "%current%"){
    			echo $post->post_title;
    		}else{
    			echo trim($instance['title']);
    		}
    
    		echo $after_title;
    		?>
    
    		<ul id="nav-subpages" role="navigation">
    		<?php echo $subpages; ?>
    		</ul>
    
    		<?php
    		echo $after_widget;
    	//}
    	$post = $tmp_post;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get count of wp_list_pages, check if results’ is closed to new replies.