Reputation: 23
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
Upvotes: 2
Views: 26839
Reputation: 1260
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 />";
} ?>
Upvotes: 3
Reputation: 21
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
Upvotes: 0
Reputation: 11
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>";
Upvotes: 1
Reputation: 14798
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;
}
Upvotes: 13