php Wordpress 在一页上显示所有页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7023310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:49:50  来源:igfitidea点击:

Wordpress display all pages on one page

phpwordpress-themingwordpress

提问by Tekdz

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..

但是如果创建了一个新页面,它就不会显示它,因为它没有这个代码和它的 ID。

Is there a way to bring all the pages in automatically?

有没有办法自动引入所有页面?

Any help will be appreciated, thanks

任何帮助将不胜感激,谢谢

回答by Dunhamzzz

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

您可以使用 获取博客的所有页面,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; 
}

回答by MohammadHossein R

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 argsfor more customized results:

接受的答案的返回数组不包含“邮政海关”(在我的情况下需要)。而且您可能需要检索具有特定属性的页面。使用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); 
?>

And use them like this:

并像这样使用它们:

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

Read more here

在这里阅读更多

回答by Xavi

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:

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

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

回答by hamidraza

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

如果您为不同的页面使用自定义模板,则仍然存在巨大的问题,您可以获得页面上的内容而不是模板文件