2017-08-19 2 views
0

子ページへのリンクを含む1つのページがあります。これまでは、各子ページのタイトルとおすすめ画像を取得することができましたが、メインのコンテンツを表示することはできません。また、子ページに使用されるカテゴリに基づいてフィルタリングするフィルタもあります。親ページのサブページコンテンツを表示できませんwordpress

これは私が現時点で持っているものです。

<div id="people" class="relative z-level--2"> 
     <?php 
$args = array(
     'post_type'  => 'page', 
     'posts_per_page' => -1, 
     'post_parent' => $post->ID, 
     'order'   => 'ASC', 
     'orderby'  => 'menu_order' 
    ); 


    $parent = new WP_Query($args); 

    if ($parent->have_posts()) : ?> 

    <?php while ($parent->have_posts()) : $parent->the_post(); ?> 
    <article class=" 
    <?php 

    $terms = get_the_category($page->ID); 
     foreach ($terms as $term) : 
     echo $term->slug; 
     endforeach; 
    ?> 
    player-card inline-block pl--m pr--s gb--l vertical-top"> 

     <div class="player-card__container transition--xfast shadow shadow--hover"> 
     <a id="playerCardLink" href="<?php the_permalink(); ?>" class="player-card__link"> 
      <div class="p--m br--s bg--light"> 

       <div class="player-card__content relative br--s overflow--hidden gb--m"> 


        <div class="player-card__img absolute t0 l0 b0 r0 z-level--2" style="background-image: url('<?php echo get_the_post_thumbnail_url($page->ID); ?>');"></div> 
        <div class="player-card__video relative"> 
        <video class="absolute width--full height--full t0 r0 " autoplay muted playsinline loop poster="<?php echo get_the_post_thumbnail_url($page->ID); ?>"> 

         <?php $file = get_field('playervideo', $page->ID); 
         $url = $file['url']; 

         ?> 
         <source src="<?php echo $url; ?>" type="video/mp4;"> 
        </video> 
        </div> 
       </div> 
       <div class="player-card__info"> 
       <h3 class="uppercase fs--xl"><?php the_title_attribute(); ?></h3> 
       <span class="strip strip--card gb--m"></span> 

       <p class="player-card__text line-overflow--three"> 
        <?php the_content() ?> 

       </p> 
       </div> 

      </div> 
      </a> 


    </div> 
    </article> 
    <?php endwhile; ?> 



<?php endif; ?> 
</div> 
+1

を介して取得してみてください。 https://codex.wordpress.org/Function_Reference/wp_reset_postdata –

答えて

0

それは動作しますが、ただ、print_r($parent); whileループの開始前およびコンテンツ配列のキーをチェックする必要があります。

そうあなたがループ内で `wp_reset_postdata`を使用する必要があります$parent = get_posts($args);代わりの$parent = new WP_Query($args);

関連する問題