类似这样的操作应该可以实现按标题排序和使用分页的技巧:
global $wp_rewrite, $wp_query;
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<?php //If top level, find children
if($post->post_parent == 0):
$children = new WP_Query(array(
\'post_type\'=>\'page\',
\'post_parent\'=>$post->ID,
\'paged\' => $paged,
\'posts_per_page\' => 20,
\'orderby\' => \'title\',
\'order\' => ASC
));
if($children->have_posts()): ?>
<ul>
<?php while ( $children->have_posts() ) : $children->the_post(); ?>
<li> <?php the_title();?> </li>
<?php endwhile; ?>
</ul>
$wp_query->query_vars[\'paged\'] > 1 ? $current = $wp_query->query_vars[\'paged\'] : $current = 1;
$pagination = array(
\'base\' => @add_query_arg(\'paged\',\'%#%\'),
\'total\' => $wp_query->max_num_pages,
\'current\' => $current
);
if( $wp_rewrite->using_permalinks() )
$pagination[\'base\'] = user_trailingslashit( trailingslashit( remove_query_arg( \'s\', get_pagenum_link( 1 ) ) ) . \'page/%#%/\', \'paged\' );
if( !empty($wp_query->query_vars[\'s\']) )
$pagination[\'add_args\'] = array( \'s\' => get_query_var( \'s\' ) ); ?>
<?php echo paginate_links( $pagination ); ?>
<?php else: ?>
<?php echo \'No children\';?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
<?php else://Not top level, display normal post ?>
<?php the_content(); ?>
<?php endif;?>
<?php endwhile; // end of the loop. ?>
<?php endif; ?>
您可以将paginate\\u links函数移动到要分页的任何位置。
至于显示条目的总数,可以在循环中使用$wp\\U查询变量。
<?php echo $wp_query->found_posts; ?>
<小时>