• wp_list_pages doesn’t allow for you to display the author, so I am trying to get the same effect with get_pages.

    However, the php code I’m using keeps getting one argument wrong.

    At the end of the foreach loop I set the term $previous_page using page_title and then at the beginning of the next loop, that value disappears.

    <?php
    					$pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
    					$count = 0;
    					$ulcount = 0;
    					$previous_parent = get_the_title($page->post_parent);
    					$previous_page = $page->post_title;
    					foreach($pages as $page)
    					{
    						$parent_page = get_the_title($page->post_parent);
    						if($previous_parent != $parent_page && $previous_page = $parent_page)
    							{
    								echo '<br />';
    								echo $previous_page;
    								echo ' (previous_page) equals ';
    								echo $parent_page;
    								echo ' (parent_page)<ul>';
    								$ulcount++;
    								echo $ulcount;
    							}
    						$content = $page->post_content;
    						if(!$content)
    							continue;
    						$count++;
    						$content = apply_filters('the_content', $content);
    					?>
    						<li>
    						<a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a> (parent: 	<?php
    							$parent_title = get_the_title($page->post_parent);
    							echo $parent_title;
    							?>)</li>
    					<?php
    					if($previous_parent != $parent_page && $previous_page != $parent_page)
    						while($ulcount > 0)
    							{
    								echo '</ul>';
    								$ulcount--;
    							}
    					$previous_parent = get_the_title($page->post_parent);
    					$previous_page = $page->post_title;
    					echo 'previous_page = ';
    					echo $previous_page;
    					}
    				?>

    The page is here http://www.wheeloftimerp.net/members/

    Let me know if you have any progress.

Viewing 3 replies - 1 through 3 (of 3 total)
  • $parent_page = get_the_title($page->post_parent);
    if($previous_parent != $parent_page && $previous_page = $parent_page)

    in that second line:
    && $previous_page = $parent_page
    is actually not as intended a comparison if these are the same ( that would be == ) but is setting the variable $previous_page to the value of $parent_page.

    so, these two lines should read:

    $parent_page = get_the_title($page->post_parent);
    if($previous_parent != $parent_page && $previous_page == $parent_page)

    Thread Starter lukekfreeman

    (@lukekfreeman)

    Ah, I can’t believe I was missing that for hours!
    Thanks so much!
    Absolute legend!

    Thread Starter lukekfreeman

    (@lukekfreeman)

    Hi all,

    I’ve managed to make get pages work for listing a page, however, if there are more than one child page at the same level and one of them has children of its own it will cut off. E.g.:

    + Level one
    -+ Level two
    -+ Level two
    –+ Level three
    —+ Level four
    + Level three

    Here’s the code. Any help is much appreciated:

    <?php
    	$pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=DESC');
    	$count = 0;
    	$ulcount = 0;
    	$previous_previous_parent = 0;
    	$previous_parent = $page->post_parent;
    	$previous_page = $page->ID;
    	foreach($pages as $page)
    	{
    		$parent_page = $page->post_parent;
    		if($previous_parent != $parent_page && $previous_page == $parent_page)
    			{
    				echo '<ul>';
    				echo $ulcount++;
    			}
    		if($previous_parent != $parent_page && $previous_page != $parent_page)
    			while($ulcount > 0)
    				{
    					echo '</ul>';
    					echo $ulcount--;
    				}
    		$content = $page->post_content;
    		if(!$content)
    			continue;
    		$count++;
    		$content = apply_filters('the_content', $content);
    	?>
    		<?php if($ulcount == 0) echo '<hr />'; ?><li>
    		<a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a> by <!--<?php echo get_userdata($page->post_author)->user_url; ?>--> <?php echo get_userdata($page->post_author)->display_name; ?> — <?php
    		if (get_post_custom_values('Character', $page->ID)==TRUE)
    			{
    		  $mykey_values = 	get_post_custom_values('Character', $page->ID);
    		  foreach ( $mykey_values as $key => $value ) {
    		    echo $value;
    			echo ', ';
    		  }
    }
    		?><?php echo mysql2date('D, M j, Y H:i a', $page->post_date);  ?></li>
    	<?php
    	$previous_previous_parent = $previous_parent;
    	$previous_parent = $page->post_parent;
    	$previous_page = $page->ID;
    	}
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Using Get Pages for Page List’ is closed to new replies.