10.对于2.0.1以后的版本,在页面模板中wp list pages按如下用,即使没有子页面,也要有 <ul>或 <ol>标签。
wp_list_pages(‘title_li=&child_of=’.$post->ID.’&show_date=modified
&date_format=$date_format’); ?>
</ul>
11.只有当前页面含有子页面时以下才可用。
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
12.当前页面为父页面或一个子页面(包含子子页面)时只显示子页面,不适用于sidebar中的widget模块。
if($post->post_parent)
$children = wp_list_pages(“title_li=&child_of=”.$post->post_parent.”&echo=0″);
else
$children = wp_list_pages(“title_li=&child_of=”.$post->ID.”&echo=0″);
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
13.下面代码用于sidebar.php:
*当前页面为主页面(如博客主页)时,sidebar中所有顶层页面列出; *当前页面为一个无子页面的顶层页面时,sidebar中所有顶层页面列出; *当前页面为包含子页面的顶层页面时,sidebar中只列出子页面和其下子页面(如果有的话); *当前页面为一个子页面时,sidebar中只显示该子页面和其下子页面。
if (is_page( )) {
$page = $post->ID;
if ($post->post_parent) {
$page = $post->post_parent;
}
$children=wp_list_pages( ‘echo=0&child_of=’ . $page . ‘&title_li=’ );
if ($children) {
$output = wp_list_pages (‘echo=0&child_of=’ . $page . ‘&title_li=
<h2>Child Pages </h2>’);
}
}
echo $output;
?>
14.列出所有子页面。
// will display the subpages of this top level page
$children = wp_list_pages(“title_li=&child_of=”.$post->ID.”&echo=0″);
}else{
// diplays only the subpages of parent level
//$children = wp_list_pages(“title_li=&child_of=”.$post->post_parent.”&echo=0″);
if($post->ancestors)
{
// now you can get the the top ID of this page
// wp is putting the ids DESC, thats why the top level ID is the last one
$ancestors = end($post->ancestors);
$children = wp_list_pages(“title_li=&child_of=”.$ancestors.”&echo=0″);
// you will always get the whole subpages list
}
}
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
15.页面项的标记和样式:默认wp_list_pages()生成一个嵌套的无序页面列表。可以通过使title_li参数留空而去掉最外层项(li.pagenav)和列表(ul),使用自己设计的样式。
所有列表项以类page_item(页面项)为标记。当显示某个页面wp_list_pages()被调用时,该页面的列表项又附加一个类current_page_item(当前页面)。
<ul>
<!– Output starts here if ‘title_li’ parameter is empty –>
<li class=”page-item-2 page_item current_page_ancestor current_page_parent”>
[parent of the current Page]
<ul>
<li class=”page-item-21 page_item current_page_item”>
[the current Page]
</li>
</ul>
</li>
<li class=”page-item-3 page_item”>
[another Page]
</li>
</ul>
</li>
样式参考:
.page_item { … } /* any Page item */
.current_page_item { … } /* the current Page */
.current_page_parent { … } /* parent of the current Page */
.current_page_ancestor { … } /* any ancestor of the current Page */
这里有英文原版文档。
文章分页: 1 2右上方更多相关内容/站内搜索-关键词请用空格隔开
发表留言