treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Wordpress Custom Fields from Sub-Page to Parent Page

  • Hello Everyone,

    I am new to wordpress theme design and php, so please excuse me if this is rudimentary.
    I am trying to setup a wordpress site that has a video archive page similar to the one on CSS-Tricks.
    I have individual video pages created as a sub-page of the video archive page.
    On the video archive page I have the individual video pages linked to dynamically using..
    <?php
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) { ?>
    <ul id=\"video-nav\">
    <?php echo $children; ?>
    </ul>
    <?php } ?>

    Also on the individual video pages, I have a custom field setup called "thumb" that I place the URL of the post thumbnail in.
    I would like to access the custom field info from the parent video page and have the image display in the list item of the dynamically generated links.

    In other words I would like to dynamically load all the images from the sub-page custom field on parent page.

    I hope that this makes sense.

    Any help is much appreciated.
  • Hi,

    As far as I know, you can only echo the meta data from inside "the_loop"

    This page has more info about Meta Data http://codex.wordpress.org/Using_Custom_Fields
  • Yeah that sounds about right. Perhaps you should do a well-executed query_posts() to get those child pages, so then you are inside the loop and have access to the page titles AND can grab that image that is a custom field.
  • If you only need a flat list of posts under the current page then simply using query_posts with a loop would be your best option. The only problem is if you have hierarchical pages, which would require nested lists, as that is a little more complicated to acheive and it is this that most of the magic inside wp_list_pages is dedicated to.

    I think you could use the following (untested) code as a starting point:

    query_posts(\"post_type=page&post_status=publish&post_parent=$post->ID&orderby=title&order=asc&showposts=-1\");
    if (have_posts()) : while(have_posts()) : the_post();

    echo '<li>' . '<img src=\"' . get_post_meta($post->ID, 'thumb', true) . '\" />' . <a href=\"' . get_page_link($post->ID) . '\" title=\"' . attribute_escape(apply_filters('the_title', $post->post_title)) . '\">' . '</li>';

    endwhile; endif;
  • How do they do this magic trick? You know that magic trick were a woman walks behind lets say a piece of wood that a guy is holding, she stands behind it for like 2 seconds and then shes wering different clothes to the one before she went behind the piece of wood. Could you please help me?
    ____________________
    yahoo keyword tool ~ overture ~ traffic estimator ~ adwords traffic estimator
  • It's all done with smoke and mirrors.
  • for some reason, I always subconsciously add "bananas" to the first line of every one of your posts...
    It's all done with smoke, bananas and mirrors.

    oh.... wait a minute... :lol:
  • smokey bananas... mmm delicious