2011-08-11 148 views
1

我需要在一个页面上显示所有页面。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 ..

有没有办法让所有页面自动进入?

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

回答

11

您可以通过使用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; 
} 
+0

的工作,非常感谢! – Tekdz

+0

返回的数组不包含任何“后海关”索引 –

1

此外,如果您使用的是二十十大主题(我不知道它是如何将他人合作),你可以很容易地得到所有的网页格式:

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

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

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

仍存在巨大的问题,如果你正在使用自定义模板为不同的页面,你就能得到上述内容而不是模板文件将单页

0

接受的答案的返回数组中不包含“岗位上海关“(我需要这个)。而且您也可能需要检索具有特定属性的页面。使用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 />"; 
} ?> 

Read more here

相关问题