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.

  • why is it down voted? It is a good question – Computer User Jan 19 '20 at 15:44
  • I've no idea. :/ – Gal Grünfeld Jan 20 '20 at 17:23

I was able to learn how to do it.

Here's a solution:

$pages = get_pages();
foreach($pages as $page) {

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()) { 
    get_template_part( 'templates/list/content', 'xxx' );


Doing this you will be able to use

get_template_part( 'templates/list/content', 'xxx' );
  • 1
    you should never use query_posts – Mark Kaplun Jul 20 '18 at 15:09
  • @MarkKaplun and why is that? – Nicolay Hekkens Jul 23 '18 at 9:17
  • 1
    because it s a horrible kludge which will break pagination and make even more unexpected fun. google for it – Mark Kaplun Jul 23 '18 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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