WordPress custom fields to display Page subtitle in navigation

The main navigation is basically a list of Pages in WordPress. In order to display a custom subtitle associated with each individual Page, I created a new custom field, called ‘Subtitle’, and assigned a value to it on each Page. The custom field is optional, and I restricted the navigation to only display parent Pages.

    'depth' => 0,
    'echo' => 0,
    'sort_column' => 'menu_order',
    'post_type' => 'page',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts' => 1,
    'meta_key' => 'Subtitle'

  $attachments = get_pages($args);

<div id="nav">
    <ul id="navLi">
    	<?php for ($i =0; $i<count($attachments); $i++) {
              $post = $attachments[$i];  ?>
              <li><a href="<?php echo get_permalink($post->ID) ?>"><?php echo $post->post_title; ?></a>
              <br/><span class="subtxt">
                  <?php echo $post->meta_value; ?>
        <?php } ?>

There you have it. The navigation is comprised of the title of the Page followed by the designated Subtitle underneath. The results, with CSS styling applied, can be seen below. Titles of the Pages are in black, Subtitles are in purple.

Page navigation w/ subtitles

Leave a Reply

Your email address will not be published. Required fields are marked *