我已使用创建自定义帖子类型“服务”\'hierarchical\' => true,
. 我的循环很简单:
while (have_posts()) {
the_post();
get_template_part(\'content\', get_post_type());
}
在admin中,我有下一个结构:服务1服务2子服务的问题是,在服务页面上,我拥有所有这些服务。但我只想要1级职位没有儿童职位。子帖子应该在父帖子内。我该怎么做?
我已使用创建自定义帖子类型“服务”\'hierarchical\' => true,
. 我的循环很简单:
while (have_posts()) {
the_post();
get_template_part(\'content\', get_post_type());
}
在admin中,我有下一个结构:服务1服务2子服务的问题是,在服务页面上,我拥有所有这些服务。但我只想要1级职位没有儿童职位。子帖子应该在父帖子内。我该怎么做?
请在此处添加自定义帖子类型名称\'post_type\' => \'Services\', // required
<?php
$args=array(
\'post_parent\' => 0, // required
\'post_type\' => \'Services\', // required
\'orderby\' => \'menu_order\', // to display according to hierarchy
\'order\' => \'ASC\', // to display according to hierarchy
\'posts_per_page\' => -1, // to display all because default is 10
);
$query = null;
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while($query->have_posts()) {
$query->the_post();
$post_id=get_the_ID();
$post=get_post($post_id,\'ARRAY_A\');
echo $post[\'ID\'].\': \'.$post[\'post_title\'].\'<br>\';
}
}
wp_reset_query($query);
?>
我想用这个循环显示最后3篇文章。这很有效,但我不知道为什么,但摘录总是一样的。我做错了什么? <?php $args = array( \'numberposts\' => \'3\' ); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_posts as $recent ){ ?> <div class=\"