在我的functions.php中我有以下代码行:
// Display 48 products per page.
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 48;' ), 20 );
这限制了商店页面和类别页面上显示的产品数量。但是,当我在产品标签上搜索时,这将在结果页面上工作。我在这里错了什么?
这将改变产品的搜索结果限制。我希望这对您有帮助。
function searchfilter($query) {
if ($query->is_search && !is_admin() ) {
$query->set('post_type',array('product'));
$query->set('posts_per_page',25);
}
return $query;
}
add_filter('pre_get_posts','searchfilter');
案例2:创建自己的
自定义搜索结果模板在名为search.php的主题中创建一个新文件,仅在搜索页面上使用。
<?php
/**
* Search Results Template File
*/
get_header(); ?>
<header>
<h1>Search Results: "<?php echo get_search_query(); ?>"</h1>
<br>
</header>
<?php if ( have_posts() ) : // results found?>
<?php while ( have_posts() ) : the_post(); ?>
<article>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
<p> <a href="<?php the_permalink(); ?>">View</a> </p>
</article>
<?php endwhile; ?>
<?php else : // no results?>
<article>
<h1>No Results Found.</h1>
</article>
<?php endif; ?>
<?php get_footer(); ?>