是否有方法检查子页是否有同级页。也就是说,它们是否属于同一父页。如果是,则显示每个子页面中的同级页面列表。
示例:
Science books
Book 1
Book 2
Book 3
当我在里面的时候:Book 1
我想以列表形式显示:Book 2
Book 3
有可能吗?是否有方法检查子页是否有同级页。也就是说,它们是否属于同一父页。如果是,则显示每个子页面中的同级页面列表。
示例:
Science books
Book 1
Book 2
Book 3
当我在里面的时候:Book 1
我想以列表形式显示:Book 2
Book 3
有可能吗?当然这是可能的。看看吧docs for wp_list_pages
所以像这样的事情可以做到:
<?php
global $post; // assuming there is global $post already set in your context
wp_list_pages( array(
\'exclude\' => $post->ID, // exclude current post
\'parent\' => $post->post_parent // get only children of parent of current post
) );
?>
如果您想使用一些自定义HTML,那么下面的内容应该会有所帮助:<?php
global $post; // assuming there is global $post already set in your context
if ( $post->post_parent ) : // if it\'s a child
$siblings = new WP_Query( array(
\'post_type\' => \'page\',
\'post_parent\' => $post->post_parent,
\'post__not_in\' => array( $post->ID )
) );
if ( $siblings->have_posts() ) :
?>
<ul>
<?php while ( $siblings->have_posts() ) : $siblings->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_postdata(); ?>
</ul>
<?php
endif;
endif;
?>
我已经创建了一个新的用户角色-供应商-能够read_private_pages, 但当我以这样的用户身份登录并转到一个私人页面时,我看不到它。以下是我的插件代码:function fc_add_role($role, $display_name, $capabilities = array()) { if (!empty($role)) { return wp_roles()->add_role( $role, $display_name, $capabili