Is it possible to loop through all the pages in a website? If so, how?
I'm building a one-pager resume website, and I want to display all of the website's pages as parts of my main page.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityIs it possible to loop through all the pages in a website? If so, how?
I'm building a one-pager resume website, and I want to display all of the website's pages as parts of my main page.
I was able to learn how to do it.
Here's a solution:
$pages = get_pages();
foreach($pages as $page) {
echo($page->post_content);
}
Are you talking about something like this:
$pages = get_pages();
foreach ($pages as $page) {
echo $page->post_title;
}
?
Of course you can sort them (sort_column
, sort_order
), filter out (exclude
) unwanted etc. by using specific arguments applied to get_pages()
function - you can check them in the Wordpress docs.
I would suggest doing this:
query_posts(array('post_type' => 'page'));
while (have_posts()) {
the_post();
get_template_part( 'templates/list/content', 'xxx' );
}
wp_reset_query();
Doing this you will be able to use
get_template_part( 'templates/list/content', 'xxx' );