Over the past seven years Wordpress has blossomed into the industry favorite blogging platform and a widely used and powerful CMS. The newly launched version 3 has ironed out a lot of complexities and made it even more robust and flexible for a beginner to dive in. While learning most of the theming and development of Wordpress based sites on-the-job, I have been taking down notes (or building a cheat sheet of my own, if you will) for quick reference. Here’s a round-up of the built-in Wordpress functions that can be used to list pages of a Wordpress site.
Listing all pages

?php wp_list_pages(); ?

Listing or excluding specific pages by ID

?php wp_list_pages(‘include=1,5′); ?

lists pages with IDs 1 and 5.

Similarly to excluding specific pages use:

?php wp_list_pages(‘exclude=2,3′); ?

this lists all pages except the ones that have IDs 2 and 3.

Sorting Pages

By default wp_list_pages list pages alphabetically. The sort_column parameter can be used in addition to sort pages differently. The possible values are post_title (alphabetically – by default), menu_order (by page order), menu_order (by date of page creation), post_modified (by last modified), ID (sort by ID), post_author (by page author ID), post_name (sort alphabetically by post).

The syntax is of the following nature:

?php wp_list_pages(’sort_column=post_date’); ?

Listing pages based on depth
This is useful in case of listing pages that have sub-level pages and you need to list only the first level of the pages but exclude subpages.

?php wp_list_pages(‘depth=1′); ?

The list pages functions are very useful for navigation menu displays. Keep reading discussions on more such built-in Wordpress functions and shortcuts available for various tasks in future blog posts.

Latest posts by Smarajit Dasgupta

  • Share/Bookmark