
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?
Leave a Comment