WordPress在一页上显示所有页面
我需要在一页上显示所有页面。
目前我正在使用它来引入每个页面:
<?php
$page_id = 5; //id example
$page_data = get_page( $page_id );
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
echo $content;
?>
但是如果创建了一个新页面,它不会显示它,因为不会有此代码及其 ID。
有没有一种方法可以自动引入所有页面?
任何帮助将不胜感激,谢谢
I need to display all the pages on the one page.
At the moment I am using this to bring in each page:
<?php
$page_id = 5; //id example
$page_data = get_page( $page_id );
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
echo $content;
?>
But if a new page is created it wont display it as wont have this code and its ID in place..
Is there a way to bring all the pages in automatically?
Any help will be appreciated, thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
get_pages();
获取博客的所有页面,在循环中执行此操作,如下所示:You can get all the pages of your blog by using
get_pages();
, do this in a loop like so:接受的答案的返回数组不包含“海关后”(我在我的情况下需要)。而且您可能需要检索具有特定属性的页面。使用
args
获得更多自定义结果:并像这样使用它们:
在此处阅读更多信息< /a>
The accepted answer's returned array doesn't contain "post customs" (which I needed in my case). And also you may need to retrieve pages with specific attributes. Use
args
for more customized results:And use them like this:
Read more here
另外,如果您使用“二十十”主题(我不知道它在其他主题中如何工作),您可以轻松地格式化所有页面:
Also, if you are using the Twenty Ten theme (I don't know how will it work in others) you can easily get all the pages formatted:
那么你也可以通过这段代码获取每个页面的内容。
如果您对不同页面使用自定义模板,仍然存在巨大问题,您可以获取内容,但不能获取一页上的模板文件
Well you can get the contents of each page by this code as well.
Still there is huge problem if you are using custom templates for different pages you can get the content but not the template files on your one page