• Resolved vavroom

    (@vavroom)


    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

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter vavroom

    (@vavroom)

    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 ??

    Thread Starter vavroom

    (@vavroom)

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

    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

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

    Thread Starter vavroom

    (@vavroom)

    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 ??

    Thanks,

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

    Sadish

    Thread Starter vavroom

    (@vavroom)

    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 ??

    Thread Starter vavroom

    (@vavroom)

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

    https://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

    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

    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);
    
    	}
      }
     ?>

    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.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘wp_list_pages and get_post_metadata’ is closed to new replies.