Grow your CSS skills. Land your dream job.

Pulling custom field data from child pages

  • # January 10, 2010 at 5:45 pm

    Hey guys,

    Wondering if this is possible, maybe ye can help me:

    I have a list at the bottom of each individual page listing all the other pages of that category (i.e. pages that have the same ‘parent’ page), for which I am using the following code. You can see a live example here: http://oldkitbag.com/cashelbay-wp/past-ponies/jjs-fiona/

    Code:
    < ?php
    if($post->post_parent)
    $children = wp_list_pages(“title_li=&child_of=”.$post->post_parent.”&echo=0″);

    else

    $children = wp_list_pages(“title_li=&child_of=”.$post->ID.”&echo=0″);
    if ($children) { ?>

    • < ?php
      if (!empty($post->post_parent)) {
      $parentTitle = get_the_title($post->post_parent);?>
      See all Ponies listed under < ?php echo $parentTitle; ?>:
      < ?php } ?>

    • < ?php echo $children; ?>

    < ?php } ?>

    It works no probs, it just looks crap. Now each of these child pages have custom fields, including thumbnails, and I’m wondering would it be possible to construct a list that not only coughs up the page titles but also the thumbnail custom field for each page as well. Any help would be greatly appreciated – even if it’s just to say its not possible! :D

    # January 13, 2010 at 1:45 pm

    You gotta run a loop if you want custom fields =)

    # January 31, 2010 at 5:36 pm

    I came accross the following at http://www.wprecipes.com/wordpress-how-to-get-custom-fields-outside-the-loop. Now, I think they are still running a loop per se – isn’t that what a wp_query is? But anyway, my point is this: could I use this code in some form to echo just the ‘thumbnail’ custom fields and the titles, both suitably permalinked, of all the pages of a given category, as in my original problem?

    Quote:
    To display a custom field value outside the loop, simply use the following code. Don’t forget to replace customField on line 4 by the name of the custom field you want to display.

    Code:
    < ?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, ‘customField’, true);
    ?>
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".