How to List Pages in Wordpress

June 19, 2009 in Wordpress How To | Comments (0)

Wordpress has a function called get_pages() that lets you pull a list of the pages and use them in a list. I’ve documented how to do that here:


<ul>
<?php
$pages =  get_pages();
foreach ($pages as $pg) {
$option = '<li><a href="'.get_page_link($pg->ID).'">';
$option .= $pg->post_title;
$option .= '</a></li>';
echo $option;
}
?>
</ul>

You’ll need a few plugins though to excecute php in your posts/pages:

  • http://plugindve.wordpress.com/ – allows you to disable visual editor for a single post
  • http://bluesome.net/post/2005/08/18/50/ – exec-php in posts

Make sure you read the settings as you have to disable and change some of the write preferences too.

I’ve tested this on wordpress 2.8, but they aren’t listed as certified.