0

I am trying to create a section on my page template that displays all the parent (top level) pages with its children listed below but only by the same author of the currently viewed page.

I have this code snippet below which perfect shows top level pages and their children below but need to tweak it so it only shows from same author.

I also need to ensure it displays the currently viewed page as well.

Is there anything simple I can add to what I have below?

<?php
$args = array(
'sort_column' => 'menu_order',
'parent' => 0,
);
$pages = get_pages($args);
foreach($pages as $page){
?>
<ul>
    <li>
    <?php 
    echo '<a href="' . get_permalink( $page->ID ) . '">' . $page-  >post_title . '</a>';
    ?>  
    </li>
    <?php  
    wp_list_pages('title_li=&depth=0&child_of='.$page->ID.'');
    ?>  
</ul>
<?php
}
?> 

I would then also like each of parent pages to have their own class and not include the actual link to the page, and then child pages to be sub items of the above class so I can create a drop down of all the users parent pages and children pages.

Thanks!

0

For anyone looking for this same solution I figured it out (apart from adding a different class to parents and children, unfortunately this puts the parent in the same nest as its children but with css and query ill be able to differentiate these.

Here is the code;

<?php
global $authordata, $post;
$authors_posts = get_posts( array(
'author' => $authordata->ID,
'post_parent' => 0,
'orderby' => 'menu_order',
'post_type' => 'page',
'posts_per_page' => 5 ) );


foreach ($authors_posts as $post)  {
?>

<ul> poo
    <li>
    <?php 
    echo '<a href="' . get_permalink( $post->ID ) . '">' . $post-  >post_title . '</a>';
    ?>  
    </li>
    <?php  
    wp_list_pages('title_li=&depth=0&child_of='.$post->ID.'');
    ?>  
 </ul>
 <?php
 }

 ?> 
|improve this answer|||||
  • If anyone can shed any light as how to how I can display the results in a drop down with the parent pages not actuating linking through but instead showing their children on click? – joelybristol Jan 13 '17 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.