WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_list_pages and get_post_metadata (12 posts)

  1. vavroom
    Member
    Posted 7 years ago #

    Hello all,

    Been hunting for an answer here and I'm not quite finding.

    I am using wp_list_pages on pages to list children pages, as such:
    <?php wp_list_pages("title_li=&child_of=".$post->ID."&sort_column=menu_order");?>

    This works great for me. However, (and there's always a but, isn't there?), we would like to display a description of each page in that list.

    I'm thinking, it's relatively straightforward, add a page description in the Custom Fields area, and then use get_post_meta to retrieve it if it exists. I can also do this.

    What I can't seem to figure out is how to insert that meta data in the list generated by wp_list_pages. so instead of <li>Page title</li> we would have <li>Page title<br />Page description</li>.

    I'd rather not just hack the function itself (hell on future upgrades).

    Any assistance would be greatly appreciated on this.

    Thanks

  2. vavroom
    Member
    Posted 7 years ago #

    I hate to do this, but... *bump*

    Anyone with a thought?

    I've tried modifying the wp_list_pages function but arrived at a major mess :(

  3. vavroom
    Member
    Posted 7 years ago #

    No one? Does no one really know the answer, or are y'all just deciding to ignore the request?

  4. sadish
    Member
    Posted 7 years ago #

    what you are asking for is a little bit tricky.

    It took a while for me to come up with this piece of code.

    open your page.php, and just after the call to the_content(), insert this piece of code.
    -- code removed--

    This piece of code, gets all the children for the given page.
    and it loops through each one of them and presents the title of the post, and the first 255 characters of the child and then a link to continue reading.

    see if this helps.

    Sadish

  5. sadish
    Member
    Posted 7 years ago #

    here is the code.
    http://pastebin.ca/401735

  6. vavroom
    Member
    Posted 7 years ago #

    sadish, you're brilliant. That did the trick. I modified slightly, getting the info to appear in a list, removing content, and replacing with a call to custom field for a page description, but that did it.

    Thank you :)

  7. sadish
    Member
    Posted 7 years ago #

    Thanks,

    Post a link to your website when you are done, I am curious to see.

    Sadish

  8. vavroom
    Member
    Posted 7 years ago #

    Will do. It's a while away before we're ready to go live with it, but when it is, I'll post it here :)

  9. vavroom
    Member
    Posted 7 years ago #

    Hello Sadish, here's the link to the site:

    http://diversityworks.co.nz

    There's some work to be done on it, mostly under the hood (keywords, descriptions, etc).

    You'll see my implementation of your suggestion in, for example, the About Us section.

    Cheers

  10. tomazpipan
    Member
    Posted 7 years ago #

    Hi guys.

    First of all; I cannot get the code that sadish posted - would you care to let in also the rest of the universe on this one ;).

    Anyhow - I am trying to do something similar, but with meta data fom pages. Here is the link .

    Cheers

  11. rareexample
    Member
    Posted 7 years ago #

    After hours of fiddling, here's what I used to finally get this working.

    This will list subpages with a link to the title and display the custom field you specify. In this case, my custom field is task. So you change task to the "key" of your custom field

    <?php
     global $wpdb;
     $children = $wpdb->get_results("SELECT * from $wpdb->posts WHERE post_type='page' AND post_parent=$post->ID ORDER BY post_title");
      if($children) {
           foreach($children as $child) {
    	     	 echo '<a href="' . get_permalink($child->ID) . '">' . $child->post_title . '</a><br clear="all">';
    			 echo get_post_meta($child->ID, 'task', TRUE);
    
    	}
      }
     ?>
  12. YAWPU
    Member
    Posted 6 years ago #

    Hi, is it possible to echo multiple custom fields using this method? What would be the correct syntax?

    What I need is a list of subpages with several custom field values for each.

    TIA.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags