我有一个名为customer_care的自定义帖子类型,它使用名为customer-care.php的模板。
我创建了一个名为联系我们的新customer_care,并创建了一个名为办公地址的孩子。
如何在联系我们(customer-care.php)上显示办公室地址儿童的永久链接。
如何显示父帖和子帖之后以及点击显示内容之后。
我也使用data-id& jquery的。
我非常感谢您提供的任何帮助!
//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
$args = array( 'posts_per_page' => 10, 'offset'=> 0, 'post_type' => 'customer_care' );
$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>
<?php
endforeach;
wp_reset_postdata();
?>
<?php //endif; ?>
<!-- END: LOOP -->
答案 0 :(得分:1)
尝试以下代码为儿童发布
<?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; ?>
答案 1 :(得分: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>