views:

92

answers:

2

How would i show let's say two custom fields from the subpages on a parent page. Here's my code so far:

<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
   <ul>
    <?php echo $children; ?>
</ul>
<?php } ?>

How would i show two custom fields titles "details6" and "details7"

+3  A: 

The get_post_meta function is what you're looking for:

<?php 

    // Get the page's children
    $children = get_pages("child_of=" . $post->ID);

    if (!empty($children)) { 
        echo '<ul>';
        foreach($children as $child) {
            // Get the 2 meta values from the child page
            $details6 = get_post_meta($child->ID, 'details6', true); 
            $details7 = get_post_meta($child->ID, 'details7', true); 

            // Display the meta values
            echo '<li>Details 6 = ' . $details6 . ', Details 7 = ' . $details7 . '</li>';
        }
        echo '</ul>';
    }        
?> 
Pat
Sweet. Any idea on how to display child pages of lets say a page called "PageA" on a different page - "PageB".Btw i got this working too. Just using a different method. See code below.
mirza
Pat, I owe you a beer for this one. Been banging my head against it all morning!
littlerobothead
A: 

This works too. It's probably more buggy then Pat's version.

    <?php
  $args = array(
'post_parent' => $post->ID,
'post_type' => 'page',
'post_status' => 'publish'

); $postslist = get_posts($args); foreach ($postslist as $post) : setup_postdata($post); ?>

    <?php the_title(); ?>
    <?php the_permalink(); ?>
    <?php the_permalink(); ?>
    <?php echo get('details8'); ?>
    <?php echo get('details9'); ?>


    <?php endforeach; ?>
mirza