首页 > 解决方案 > WordPress Loop Post Types as List und inset sub-posts in

问题描述

我有点卡住了。我需要输出带有自定义链接的 CPType 列表。到目前为止一切正常。但我无法让子页面出现在子列表中。

这是我的代码:

<? php
function theme_name_book_show_children($post) {
$my_query = new WP_Query( 'post_type=dokumentation', 'posts_per_page=>-1', 'post_parent=>$post_parent' );

while ( $my_query->have_posts() ) :
    $my_query->the_post();

echo '<li class="page_item ps2id"><a href="#' . get_the_id() . '">' . get_the_title() . '</a></li>';

endwhile;
}

对此有什么解决办法吗?据我所知,列表页面仅提供永久链接。但由于它是一个巨大的单页纸,我需要将它链接到#ID。

感谢您的阅读!

麦克风

标签: wordpressnavigation

解决方案


function theme_name_book_show_children($parent_id) {
  global $post;
  $my_query = new WP_Query( array(
    'post_type'=>'dokumentation', 
    'posts_per_page'=>-1, 
    'post_parent'=>$parent_id 
  ) );

  while ( $my_query->have_posts() ) : $my_query->the_post();    
    echo '<li class="page_item ps2id"><a href="#' . $post->ID . '">' . get_the_title() . '</a></li>';    
  endwhile;
  wp_reset_postdata();

}

推荐阅读