wordpress - 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。
感谢您的阅读!
麦克风
解决方案
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();
}
推荐阅读
- regex - Nginx location's regex, is escaping the forward slash needed?
- html - 使用 ngModel,禁用 html 选项默认选择
- linux - On OpenConnect VPN, Docker containers have DNS but host machine does not
- java - Disk Free decrease in a directory containing only live lucene indexes
- spark-ar-studio - How to convert screen boundaries to local coordinates in Spark AR?
- grid - ExtJs 6:如何通过已知位置直接获取特定网格单元组件
- node.js - 将缓冲区转换为十六进制字符串
- javascript - Chart JS: All Values Displayed on x-axis After Callback Conversion
- java - How to inherit custom @EnableAutoConfiguration annotation in junit tests?
- c# - netOffice Outlook AppointmentItem 按共享文件夹中的 EntryID 筛选