wordpress的wp_list_pages()详解

来源:互联网 发布:淘宝访问受限代理软件 编辑:程序博客网 时间:2024/05/22 10:03
wordpress的wp_list_pages()详解
显示列表中特定页面
若仅希望在列表中显示特定页面,例如编号为35,7,26和13的页面,可使用include参数。
<ul>
<?php wp_list_pages('include=7,13,26,35&title_li=<h2>' . __('Pages') . '</h2>' ); ?>
</ul>
显示子页面
2.0.1之前版本:
将以下代码存入WordPress主题page.php模板中the_content( )之后的the_post版块中,或存入page.php模板的副本中,供含有子页面的页面使用:
<ul>
<?php
global $id;
wp_list_pages("title_li=&child_of=$id&show_date=modified
&date_format=$date_format"); ?>
</ul>
由于未设置全局变量$id,本代码无法在WordPress2.0.1及之后版本的页面模板中运行。2.0.1及之后版本中可使用下面介绍的代码。
WordPress 2.0.1及之后版本:
注意:即使没有子页面,HTML标签也是必要的(<ul>或<ol>)。用css设置列表时需要将这一点谨记在心。
<ul>
<?php
wp_list_pages('title_li=&child_of='.$post->ID.'&show_date=modified
&date_format=$date_format'); ?>
</ul>
以下代码仅在目前页面有子页面(将目前页面设为父级页面的页面)的情况下生成列表:
<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
原创粉丝点击