2017-05-04 141 views
0

我有一个名为customer_care的自定义帖子类型,它使用一个名为customer-care.php的模板。如何使用自定义帖子类型在父帖子类型中显示子帖子类型?

我创建了一个新的customer_care,叫做联系我们,并创建了一个叫做办公地址的孩子。

如何获取办公地址孩子的永久链接显示在联系我们(customer-care.php)上。

如何显示家长帖子和孩子帖子后和点击后显示内容。

我也使用数据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> 
相关问题