问题描述
|
这是我到目前为止所拥有的。不幸的是,这抓住了我所有页面的标题和内容,包括子页面。我只想显示顶级主页。我怎样才能做到这一点?
<?PHP query_posts(\'post_type=page\'); ?>
<?PHP if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?PHP the_title(); ?>
<?PHP the_content(); ?>
<?PHP endwhile; endif; ?>
*注意:我想同时显示页面的标题和内容。不只是标题。否则我会使用:
<?PHP wp_list_pages(\'depth=1\'); ?>
更新:按照konsolenfreddy的建议,我能够正确地浏览我的页面。但是出现了一个新问题。内容正在剥离其标签。反正我可以保留它们吗?这是我的新代码:
<?PHP
$pages = get_pages(\'parent=0\');
foreach ($pages as $pagg) {
$option .= $pagg->post_title;
$option .= $pagg->post_content;
echo $option;
}
?>
解决方法
您可以使用
get_pages()
(请参阅http://codex.wordpress.org/Function_Reference/get_pages),它的参数与wp_list_pages()
相同
, 这样行吗?
<?php query_posts(\'post_type=page&post_parent=\'.$parent);?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>