• I am currently using the following code to dynamically list parent and child pages of a given section of a website:

    <?php if($post->post_parent) {
    	$parent_link = get_permalink($post->post_parent); ?>
    
    	<?php
    	$parent_title = get_the_title($post->post_parent);
    	echo $parent_title;
    	?>
    
    	<?php  }
    	else { ?>
    	<?php
    	$parent_title = get_the_title($post->post_parent);
    	echo $parent_title;
    	?>
    
    	<?php }
    	?>
    	</p>
    
    	<?php
     	if($post->post_parent)
      	$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
      	else
      	$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
      	if ($children) { ?>
      	<ul>
      	<?php echo $children; ?>
      	</ul>
      	<?php } ?>

    This works great. You can see an example of it working properly here: http://rnche.com/ostc/education/youth-education/

    However, I have created some Custom Post Types to display events, and when I call these events in the main content area of a template that uses the same code above for the sidebar, the page seems to forget where it’s at. It displays the title of the first event, and only that, instead.

    Here is the incorrect nav: http://rnche.com/ostc/on-stage/2013-season/

    And a page in the same category that displays the left-nav properly (because it’s not calling any event posts in the main content area): http://rnche.com/ostc/on-stage/2012-season/

    I can’t figure out why the page doesn’t know where it is now that I’ve added posts. Help?

    Thanks in advance,
    Dave

Viewing 4 replies - 1 through 4 (of 4 total)
  • when I call these events in the main content area of a template

    how?
    what code are you using for this?
    do you reset the query after this section?

    http://codex.wordpress.org/Function_Reference/wp_reset_query

    Thread Starter theswimmer

    (@driensche)

    I’m calling with this:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <div class="event">
    
    <?php $photos = aldenta_get_images('full');
    
    if ($photos) {
    	foreach ($photos as $photo) {
    		echo "$photo";
    	}
    }
    ?>
    
    <h2><?php the_title(); ?></h2>
    <p><?php the_content(); ?></p>
    </div>
    
    <?php endwhile; else: ?>
    
     <!-- The very first "if" tested to see if there were any Posts to -->
     <!-- display.  This "else" part tells what do if there weren't any. -->
     <p>Sorry, no posts matched your criteria.</p>
    
    <?php endif; ?>

    I just tried adding the reset query just before the loop end, like this:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <div class="event">
    
    <?php $photos = aldenta_get_images('full');
    
    if ($photos) {
    	foreach ($photos as $photo) {
    		echo "$photo";
    	}
    }
    ?>
    
    <h2><?php the_title(); ?></h2>
    <p><?php the_content(); ?></p>
    </div>
    
    <?php endwhile; else: ?>
    
     <!-- The very first "if" tested to see if there were any Posts to -->
     <!-- display.  This "else" part tells what do if there weren't any. -->
     <p>Sorry, no posts matched your criteria.</p>
    
     <?php wp_reset_query(); ?>
    
    <?php endif; ?>

    and no luck. Any other direction?

    try and add this <?php wp_reset_query(); ?> after the <?php endif; ?>

    where it is now, it would only get called if there are no posts.

    Thread Starter theswimmer

    (@driensche)

    Wah! That did it! Thank you, alchymyth!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_list_pages loses its place when I add posts to a page’ is closed to new replies.