我试图覆盖搜索分页时显示的帖子数量。php模板,16对4。在后端的阅读设置中,它被设置为4,这是需要的,因为我的首页使用相同的代码来显示最近的4篇文章。
有没有办法在搜索中指定此项。php模板页?
这是我的搜索模板页。php
<?php
get_header();
global $wp_query;
?>
<picture class="featured-image block pos-rel">
<div class="t-con flex row pos-abs">
<h1 class="post-title f-center" title="<?php echo $wp_query->found_posts; ?> <?php _e( \'Search Results Found For\', \'locale\' ); ?>: <?php the_search_query(); ?>"><?php echo $wp_query->found_posts; ?> <?php _e( \'Search Results Found For\', \'locale\' ); ?>: "<?php the_search_query(); ?>"</h1> <!--Edit these values to adjust page being shown.-->
</div>
<?php echo get_the_post_thumbnail($page=2, \'full\', array(
\'class\' => \'featured\'
)); ?>
</picture>
<section class="main bg-darkpurple">
<div>
<div class="grid row posts">
<?php while ( have_posts() ) : the_post(); ?>
<div class="col">
<div class="date-container">
<p class="post-date bg-darkpurple">
<?php
$u_time = get_the_time(\'U\');
$u_modified_time = get_the_modified_time(\'U\');
if ($u_modified_time >= $u_time + 86400) {
echo "Last updated ";
the_modified_time(\'F jS, Y\');
echo ""; }
else {echo "Posted "; the_time(\'F jS, Y\');}
?>
</p>
</div>
<?php
$primary_cat = get_post_meta($post->ID , \'_category_permalink\', true);
if ( $primary_cat != null ) {
$cat_id = $primary_cat[\'category\'];
$category = get_category($cat_id);
} else {
$categories = get_the_category();
$category = $categories[0];
}
$category_link = get_category_link($category);
$category_name = $category->name;
?>
<picture class="post-thumb block">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(\'medium\'); ?></a>
<div class="cat-container">
<a class="post-cat bg-darkpurple" href="<?php echo $category_link ?>"><?php echo $category_name ?></a>
</div>
</picture>
<h3>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<p><?php echo substr(get_the_excerpt(), 0,160); ?></p>
</div>
<?php endwhile; ?>
</div>
<div class="pagination flex row f-center">
<?php
echo paginate_links( array(
\'end_size\' => 2,
\'mid_size\' => 1,
\'prev_text\' => sprintf( \'<i></i> %1$s\', __( \'Other results\', \'text-domain\' ) ),
\'next_text\' => sprintf( \'%1$s <i></i>\', __( \'Other results\', \'text-domain\' ) ),
) );
?>
</div>
<?php wp_reset_postdata(); ?>
</div>
</section>
<?php get_footer(); ?>
我知道这行代码应该是我所需要的,但我不确定该放在哪里:\'posts_per_page\' => 16
谢谢你的帮助!