0

This question has been asked a couple of times and previous answers have helped me get where I am.

The goal:

Display direct child page on parent page regardless of level

Example:

parent 1

-child 1

--child 1.1

parent 1 displays child 1

child 1 display child 1.1

The current situation:

parent 1 displays child 1

child 1 doesn't display child 1.1 (it gets data of child 1 (current page) instead)

My current code is as follow:

$mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc', 'parent' => $post->ID ) );
                foreach( $mypages as $page ) {      
            $content = $page->post_content;
            if ( ! $content ) // Check for empty page
                continue;

            $content = apply_filters( 'the_content', $content );
        ?>

        <a  class="figurelink" href="<?php echo get_page_link( $page->ID ); ?>"><figure class="figsmall">

            <img src=" <?php the_field('thumb', $page->ID); ?> " width="207" height="141" alt="0" data-width-desktop="920" data-height-desktop="215" data-cssclass-desktop="desktop" data-width-mobile-high-res="920" data-height-mobile-high-res="215" data-cssclass-mobile-high-res="mobile-high-res"  data-width-mobile-low-res="768" data-height-mobile-low-res="179" data-cssclass-mobile-low-res="mobile-low-res">
                                <figcaption class="figsmall"><?php echo $page->post_title; ?></figcaption>        
                            </figure></a>                               
          <?php }?></div>
        </div>

Note that the_field()is getting custom field

This code is in a page template used by parent and child.

Hope this is clear and you guys can give me a hand.

  • 1
    Have you tried removing 'parent' => $post->ID from the get_pages parameters? and/or removing 'child_of' => $post->ID (leaving in the parent parameter)? – Michelle Dec 2 '14 at 18:46
  • yes if i remove 'parent' => $post->ID it displays every child and subchild (i only want direct child) on child page it displays child as well as current page (weird) – Alex Vidal Dec 2 '14 at 18:53
  • removing 'child_of' => $post->ID has no effect, therefore i can actually get rid of it. but it doesnt help – Alex Vidal Dec 2 '14 at 18:54
-1

The problem was only with one set of parent-child. Deleting them and recreating the page solved the issue.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.