Post Pic

How to use a custom blurb when listing pages

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

Jan 18 2009 11:56

If you give some demo then i will be happy… i am a newbie..

Jan 18 2009 17:03

If you give some demo and picture of the display then i will be happy .I’m a newer

Jan 18 2009 18:04

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.

Jan 18 2009 18:27

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 :)

Jan 19 2009 04:08

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?

Apr 30 2010 02:51

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!

Apr 30 2010 02:53

Oh, and the active page/menu item needs a different class!

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required