admin管理员组

文章数量:1122832

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!

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!

Share Improve this question edited Jan 12, 2017 at 9:40 joelybristol asked Jan 12, 2017 at 8:45 joelybristoljoelybristol 1432 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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
 }

 ?> 

本文标签: menusShow all parent pages and their children below from same author as currently viewed page