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 badges1 Answer
Reset to default 0For 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
版权声明:本文标题:menus - Show all parent pages and their children below from same author as currently viewed page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736287661a1927928.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论