Loop through specific pages in WordPress

Sometimes you might want specific pages to be displayed on your site. If you want to display specific posts you can place them into the same category and loop though them by cat.  However, you can’t do that with pages.  In order to solve that, this is what you have to do if you want to loop through specific pages:

Copy this code where you would like to use it and in the assignment of variable $args modify the array with the IDs of the pages you want to use. In case you don’t know how to find your page ID, simply open up the editor for the Page you want.  In the URL area you will see the page number mentioned in the http string.  It will look something like this: ‘post=74’. That is your page ID number.  Check out this guide for a visual on how to do this.

Next, add your own content inside the loop. Don’t forget to close out your php tags if your content will include html. For example:

That’s it really.  Here is an example of the code of a loop through specific pages that i created to make a mosaic of images that link to specific pages.

Enjoy, and if you have any questions, leave them in the comments below.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Are you ready for a new website?

Yes, let's start!