
In this recipe, I’m going to show you how to get a list of pages along with a custom key from each page, used to create a description.

In this recipe, I’m going to show you how to get a list of pages along with a custom key from each page, used to create a description.
The first thing to do is to paste the following code where you want your pages to be listed. It can be your sidebar, or a page template, for exemple.
<?php
$pages = get_pages();
foreach($pages as $page) {
$custom_blurb = get_post_meta($page->ID, 'custom_blurb', true);
echo "<h3><a href=\"".get_page_link($page->ID)."\">$page->post_title</a></h3>";
echo $custom_blurb;
}
?>
Once you saved your file, write some pages and add the custom_blurb custom field. As a value, give a description of the page.
Your pages will now be listed along with a custom description. Nice, isn't it?
8 Responses
If you give some demo then i will be happy… i am a newbie..
If you give some demo and picture of the display then i will be happy .I’m a newer
When considering modifications to my code and my site, I always check to see if the author of the modification is implementing it on his/her site. If I don’t see it being used then I figure it’s not worth using. The only thing that might change my mind is a demo and if one isn’t available then I definitely wouldn’t consider using it.
I’d like to make demos or screenshots, but if I want to keep the 1 day/1post frequency, I can’t take too much time on posts.
But I keep this idea for the future
An example of the blurb usage would have been good. Why mess with the code if you don’t know what you’re going to get?
How can I exclude pages from the list?
Or better yet, control the pages that will display through PageMash?
Or even better, how can you add descriptions to the new WordPress 3.0 menu display?
This is what I need to achieve:
Menu Title
span/Menu Description/span
Thanks!
Oh, and the active page/menu item needs a different class!
Trackbacks: