WordPress在一页上显示所有页面

发布于 2024-11-29 01:37:39 字数 367 浏览 1 评论 0原文

我需要在一页上显示所有页面。

目前我正在使用它来引入每个页面:

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

厌倦 2024-12-06 01:37:39

您可以使用 get_pages(); 获取博客的所有页面,在循环中执行此操作,如下所示:

$pages = get_pages(); 
foreach ($pages as $page_data) {
    $content = apply_filters('the_content', $page_data->post_content); 
    $title = $page_data->post_title; 
    echo $content; 
}

You can get all the pages of your blog by using get_pages();, do this in a loop like so:

$pages = get_pages(); 
foreach ($pages as $page_data) {
    $content = apply_filters('the_content', $page_data->post_content); 
    $title = $page_data->post_title; 
    echo $content; 
}
月竹挽风 2024-12-06 01:37:39

接受的答案的返回数组不包含“海关后”(我在我的情况下需要)。而且您可能需要检索具有特定属性的页面。使用 args 获得更多自定义结果:

<?php $args = array(
    'sort_order' => 'asc',
    'sort_column' => 'post_title',
    'hierarchical' => 1,
    'exclude' => '',
    'include' => '',
    'meta_key' => '',
    'meta_value' => '',
    'authors' => '',
    'child_of' => 0,
    'parent' => -1,
    'exclude_tree' => '',
    'number' => '',
    'offset' => 0,
    'post_type' => 'page',
    'post_status' => 'publish'
); 
$pages = get_pages($args); 
?>

并像这样使用它们:

<?php
    foreach ($pages as $page) {
    $title = $page->post_title; 
    echo $title. "<br />";
} ?>

在此处阅读更多信息< /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:

<?php $args = array(
    'sort_order' => 'asc',
    'sort_column' => 'post_title',
    'hierarchical' => 1,
    'exclude' => '',
    'include' => '',
    'meta_key' => '',
    'meta_value' => '',
    'authors' => '',
    'child_of' => 0,
    'parent' => -1,
    'exclude_tree' => '',
    'number' => '',
    'offset' => 0,
    'post_type' => 'page',
    'post_status' => 'publish'
); 
$pages = get_pages($args); 
?>

And use them like this:

<?php
    foreach ($pages as $page) {
    $title = $page->post_title; 
    echo $title. "<br />";
} ?>

Read more here

飘过的浮云 2024-12-06 01:37:39

另外,如果您使用“二十十”主题(我不知道它在其他主题中如何工作),您可以轻松地格式化所有页面:

echo "<h1 class=\"entry-title\">".$title."</h1>"
    ."<div class=\"entry-content\">".$content."</div>";

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:

echo "<h1 class=\"entry-title\">".$title."</h1>"
    ."<div class=\"entry-content\">".$content."</div>";
拥抱影子 2024-12-06 01:37:39

那么你也可以通过这段代码获取每个页面的内容。

$content = apply_filters( 'the_content', $content );

如果您对不同页面使用自定义模板,仍然存在巨大问题,您可以获取内容,但不能获取一页上的模板文件

Well you can get the contents of each page by this code as well.

$content = apply_filters( 'the_content', $content );

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文