0
我直接從代碼中未經編輯的&此代碼,它基本上列出了當前頁面的子代。但是,我想刪除父/祖的列表。非常感激任何的幫助。WordPress - 從此刪除祖先列表
謝謝!
<?php
//if the post has a parent
if($post->post_parent){
//collect ancestor pages
$relations = get_post_ancestors($post->ID);
//get child pages
$result = $wpdb->get_results("SELECT ID FROM wp_posts WHERE post_parent = $post->ID AND post_type='page'");
if ($result){
foreach($result as $pageID){
array_push($relations, $pageID->ID);
}
}
//add current post to pages
array_push($relations, $post->ID);
//get comma delimited list of children and parents and self
$relations_string = implode(",",$relations);
//use include to list only the collected pages.
$sidelinks = wp_list_pages("title_li=&echo=0&include=".$relations_string);
}else{
// display only main level and children
$sidelinks = wp_list_pages("title_li=&echo=0&depth=1&child_of=".$post->ID);
}
if ($sidelinks) { ?>
<h2><?php the_title(); ?></h2>
<ul>
<?php //links in <li> tags
echo $sidelinks; ?>
</ul>
<?php } ?>
這是完美的,工程完全按照我想要的。謝謝你Nimle的幫助:) – user2325396
嗨Nimle,我如何列出只有一層兒童而不是多層? Thx – user2325396
您可以添加其他參數進行過濾:深度可能是您想要的。例如,depth = 1 wp_list_pages(「depth = 1&title_li =&child_of =」。$ post-> ID。「&echo = 0」); 或者如果你想看到但不打印,你可以檢查孩子的父母id,看它是否等於當前的帖子ID。如果不是,那就意味着它不是一個直接的孩子。 – Selay