2017-05-04 22 views
0

私は、customer-care.phpというテンプレートを使用するcustomer_careというカスタム投稿タイプを持っています。カスタム投稿タイプを使用して親投稿タイプに子投稿タイプを表示するにはどうすればよいですか?

私は連絡先と呼ばれる新しいcustomer_careを作成し、このオフィスアドレスと呼ばれる子を作成しました。

どのように連絡先(customer-care.php)にオフィスアドレスの子供のパーマリンクを表示させるのですか?

親の投稿を表示する方法と、子供の投稿を表示した後にコンテンツを表示する方法をクリックする方法。

私もdata-id & jqueryを使用しています。

私は何か助けていただければ幸いです!

//for display parent post 
 

 
<?php 
 
\t $args = array('posts_per_page' => 10, 'offset'=> 0, 'orderby' => 'menu_order' , 'post_type' => 'customer_care'); 
 
\t \t \t \t \t \t 
 
\t $myposts = get_posts($args); 
 
\t \t 
 
\t foreach ($myposts as $post) : setup_postdata($post); 
 
?> 
 
<li><a class="service-category-select" data-id="<?php echo strtolower($post->post_title);?>"><?php the_title() ?><span class="arrow"></span></a></li> 
 
\t <?php 
 
\t \t \t endforeach; 
 
\t \t \t wp_reset_postdata(); 
 
       ?> 
 
\t \t \t \t 
 
//for display child post 
 

 
<!-- START: LOOP --> 
 
<?php 
 
\t \t $args = array('posts_per_page' => 10, 'offset'=> 0, 'post_type' => 'customer_care'); 
 
\t \t \t \t \t \t 
 
\t $myposts = get_posts($args); 
 
\t \t 
 
     foreach ($myposts as $post) : setup_postdata($post); 
 
?> 
 
\t <nav class="sub-content ng-hide" data-id="<?php echo strtolower($post->post_title); ?>"> 
 
\t \t \t \t <header class="title"><a class="service-list"><span class="arrow"></span><?php echo $post->post_title ?></a></header> 
 
\t \t \t \t <ul> 
 
\t \t \t \t 
 
\t \t \t \t \t <li> 
 
\t \t \t \t \t \t <a class="service-detail-selector" data-id="customer-care">Customer care <span class="arrow"></span></a> 
 
\t \t \t \t \t </li> 
 
\t \t \t \t \t 
 
\t \t \t \t </ul> 
 
\t \t \t </nav> 
 
\t \t \t \t <?php 
 
\t \t \t \t \t \t endforeach; \t \t 
 
\t \t \t \t \t \t wp_reset_postdata(); 
 
\t \t \t \t ?> 
 
       <?php //endif; ?> 
 
       <!-- END: LOOP -->

+0

を投稿例:https://codex.wordpress.org/Function_Reference/get_children –

+0

もこれを試して...動作しない – bhautikmodi8

+0

あなたのコードを共有してください –

答えて

0

子供のためのコードの下にこれを試して

<?php 
    $currentPostId = get_the_ID(); 
    $args = array(
      'post_type' => 'customer_care', 
      'post_parent' => $currentPostId 
     ); 
    $posts = new WP_Query($args); 

    if($posts->have_posts()): while($posts->have_posts()) : $posts->the_post(); ?> 

       <?php if(has_post_thumbnail()) { ?> 
         <?php the_post_thumbnail(); ?> 
       <?php } ?> 


       <?php echo get_the_title(); ?> 

        <?php the_excerpt(); ?> 


    <?php endwhile; endif; ?> 
0
//for display parent post 

<?php 
    $args = array('posts_per_page' => 10, 'offset'=> 0, 'orderby' => 'menu_order' , 'post_type' => 'customer_care'); 

    $myposts = get_posts($args); 

    foreach ($myposts as $post) : setup_postdata($post); 
?> 
<li><a class="service-category-select" data-id="<?php echo strtolower($post->post_title);?>"><?php the_title() ?><span class="arrow"></span></a></li> 
    <?php 
      endforeach; 
      wp_reset_postdata(); 
       ?> 

//for display child post 

<!-- START: LOOP --> 
<?php 
    $currentPostId = get_the_ID(); 
    $args = array('posts_per_page' => 10, 'offset'=> 0, 'post_type' => 'customer_care', 'post_parent' => $currentPostId); 

    $myposts = get_posts($args); 

     foreach ($myposts as $post) : setup_postdata($post); 
?> 
    <nav class="sub-content ng-hide" data-id="<?php echo strtolower($post->post_title); ?>"> 
       <header class="title"><a class="service-list"><span class="arrow"></span><?php echo $post->post_title ?></a></header> 
       <ul> 

        <li> 
         <a class="service-detail-selector" data-id="customer-care">Customer care <span class="arrow"></span></a> 
        </li> 

       </ul> 
      </nav> 
関連する問題