1

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.

2
  • why is it down voted? It is a good question Jan 19, 2020 at 15:44
  • I've no idea. :/ Jan 20, 2020 at 17:23

3 Answers 3

6

I was able to learn how to do it.

Here's a solution:

$pages = get_pages();
foreach($pages as $page) {
    echo($page->post_content);
}
1

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.

-1

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' );
3
  • 1
    you should never use query_posts Jul 20, 2018 at 15:09
  • @MarkKaplun and why is that? Jul 23, 2018 at 9:17
  • 1
    because it s a horrible kludge which will break pagination and make even more unexpected fun. google for it Jul 23, 2018 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.