我有一个使用wordpress的webblog我正在使用wp_list_pages()函数来获取列表中的子页面链接(不包括主页面)列表,我尝试了以下代码,但它返回了所有页面子页面。
我也试过这个论据 child_of ,但它不开心。请建议我尝试了很多东西......
<?php
$output = wp_list_pages('echo=0&depth=1&child_of=0');
if (is_page( )) {
$page = $post->ID;
if ($post->post_parent) {
$page = $post->post_parent;
}
}
echo $output;
?>
答案 0 :(得分:0)
此代码将列出当前页面的子页面和兄弟:
<?php
global $wp_query;
if( empty($wp_query->post->post_parent) ) {
$parent = $wp_query->post->ID;
}
else {
$parent = $wp_query->post->post_parent;
} ?>
<?php if(wp_list_pages("title_li=&child_of=$parent&echo=0" )): ?>
<div id="submenu">
<ul>
<?php wp_list_pages("title_li=&child_of=$parent" ); ?>
</ul>
</div>
<?php endif; ?>
答案 1 :(得分:0)
U can try this code this code may be useful to u
<?php
global $wpdb, $post;
$child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); ?>
<?php if ( $child_pages ) :
foreach ( $child_pages as $pageChild ) :
setup_postdata( $pageChild ); ?>
<h2 class="subpagetitle">
<a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark"
title="<?php echo $pageChild->post_title; ?>">
<?php echo $pageChild->post_title; ?>
</a>
</h2>
<?php endforeach; endif; ?>