7Apr2008
In a recent article I outlined how to modify the output of the wp_list_pages() template function in WordPress. Later on, however, I found that having the <span> tags that I added in every single title was not desirable. So instead of using a filter I wrote a small bit of custom code to iterate through my pages instead of using wp_list_pages(). Here is how to do it.
Wherever you need to output your pages just use some code like this:
$pages = get_pages(''); if($pages) { foreach($pages as $page) { // Echo your page listing here // Use : $page->ID // : $page->page_title // : the_permalink($page->ID) } }





I just placed this code on my page, exactly where wp_list_pages() used to be, but it isn’t working- is this function incompatible with WP 2.5?
Is should be compatible. I am running that exact code on another blog: skydiving-videos.com in the header.php file. I know this is a silly question, but do you have any pages published? Also, are you getting any errors or does it just not do anything? Finally, did you replace the commented code in the above example with PHP that will actually print the page the way you want it? If you simply cut-n-pasted the above example then it would not print anything because there is nothing telling it to inside the foreach loop.
hey,
Just the code I was looking for, however there seems to be a problem when I use it.
I’ve got the code exactly the way you posted it (Except I’ve got ’sort_column=menu_order’ as a parameter to the get_pages), and I’ve changed the commented line inside the loop to:
echo “\t $page->page_title \n”;
it outputs empty tags, one for each page in the DB. I modified the code to:
echo “\t $page->ID \n”;
And it works as expected (printing the IDs inside the tags)
I’m not sure how I messed this one up, any help would be much appreciated
PS where would I find the API for get_pages and for the $page structure?
Hi,
I looked through classes.php and I found what I was looking for, if I used:
$page->post_title
it works.