Php 家长提供的Wordpress列表页面
我需要一些帮助来为我的网站导航,但我不知道如何使用Wordpress“Php 家长提供的Wordpress列表页面,php,wordpress,Php,Wordpress,我需要一些帮助来为我的网站导航,但我不知道如何使用Wordpress“wp\u list\u pages()函数来完成导航 作为参考,上的导航系统应该给出我的目标的确切想法 在我尝试使用wp\u list\u页面(“child\u of=”.$post->parent\u post)之前,页面似乎只显示wrt,它是直接的父页面,而忘记了它的祖先。我已经试了一段时间了,但我就是想不起来 任何想法都很好请尝试使用此代码列出当前页面及其祖先和子页面- <?php //if the post ha
wp\u list\u pages()
函数来完成导航
作为参考,上的导航系统应该给出我的目标的确切想法
在我尝试使用wp\u list\u页面(“child\u of=”.$post->parent\u post)
之前,页面似乎只显示wrt,它是直接的父页面,而忘记了它的祖先。我已经试了一段时间了,但我就是想不起来
任何想法都很好请尝试使用此代码列出当前页面及其祖先和子页面-
<?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 } ?>
哦,如果这能让你们中的任何一个人轻松,那么网站深度会下降到三个,我想说这是相当浅的,所以如果有快速的欺骗或技巧,那将是最好的。谢谢大家。你们可以在WordPress堆栈交换中发布这个