您可以在下面找到用于显示搜索结果页面的模板。将代码添加到search.php 文件如果已安装WP-PageNavi 如果搜索结果包含10个以上的项目,那么您将看到分页。
<?php
/**
* The template for displaying Search Results pages.
*/
get_header();
?>
<h2><?php printf( __( \'Search Results for: %s\', \'themedomain\' ), \'<strong>"\' . get_search_query() . \'"</strong>\' ); ?></h2>
<div class="posts">
<?php
global $paged;
$s = $_GET[\'s\'];
$post_types = array(\'post\', \'page\');
$args=array(
\'post_type\' => $post_types,
\'post_status\' => \'publish\',
\'s\' => $s,
\'orderby\' => \'date\',
\'order\' => \'desc\',
\'posts_per_page\' => 10,
\'paged\' => $paged
);
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post();
?>
<!-- post-box -->
<article class="post-box">
<div class="meta">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p><?php _e(\'Posted by\',\'themedomain\');?> <?php if (!get_the_author_meta(\'first_name\') && !get_the_author_meta(\'last_name\')) { the_author_posts_link(); } else { echo \'<a href="\'.get_author_posts_url(get_the_author_meta(\'ID\')).\'">\'.get_the_author_meta(\'first_name\').\' \'.get_the_author_meta(\'last_name\').\'</a>\'; } ?> <?php _e(\'· on\',\'themedomain\');?> <?php echo get_the_time(\'F d, Y\'); ?> <?php _e(\'· in\',\'themedomain\');?> <?php the_category(\', \') ?> <?php _e(\'· with\',\'themedomain\');?> <?php comments_popup_link(__(\'0 Comments\', \'themedomain\'),__(\'1 Comment\', \'themedomain\'), __(\'% Comments\', \'themedomain\')); ?></p>
</div>
<?php the_excerpt(); ?>
<p><a href="<?php the_permalink(); ?>"><?php _e(\'Continue Reading →\',\'themedomain\'); ?></a></p>
</article>
<?php
endwhile;
endif;
?>
</div>
<!-- paging -->
<div class="paging">
<ul>
<?php
if(function_exists(\'wp_pagenavi\')) { wp_pagenavi(); }
?>
</ul>
</div>
<;?php get\\u footer();?>