我正在使用(并且喜欢)用于 WordPress 的 Relevanssi 插件。尽管在用户搜索中记录了两次搜索,但存在问题。
在搜索我的搜索模板时,我只是删除了所有内容,然后零碎地添加内容,直到再次获得双重结果。
这是我的搜索模板中似乎是麻烦制造者的行,但我不一定明白为什么。
<div style="background-image: url();"></div>
这对我来说是 0 意义。如果那位 STATIC html 在content-search.php
模板中,我会记录双重搜索。如果我删除它,或者如果所有文章都有get_the_post_thumbnail_url
s,那么我只会记录一次搜索。
这似乎与style="background-image:url();"
没有价值有关?
这是更大的图景:
搜索.php:
<?php
global $wp_query;
if ( $wp_query->found_posts > 12 ) {
$search_count = '1 - ' . $wp_query->post_count . ' of ' . $wp_query->found_posts;
} else {
$search_count = $wp_query->post_count;
}
?>
<div class="search-pg-header">
<?php include get_template_directory() . '/templates/partials/search-form.php'; ?>
<?php if ( get_search_query() !== '' ) { ?>
<h1>Showing <?php echo $search_count; ?> results for <?php echo get_search_query() ?></h1>
<?php } // end if ?>
</div>
<div class="posts-container">
<?php if ( have_posts() ):
while ( have_posts() ) : the_post();
get_template_part( 'templates/content', 'search' );
endwhile;
else: ?>
<p>There are no articles that matched your search.</p>
<?php endif; ?>
</div>
<?php if ( $wp_query->max_num_pages > 1 ) { ?>
<button>Show More</button>
<?php } // end if ?>
内容搜索.php:
<article data-link="<?php the_permalink(); ?>">
<div style="background-image: url(<?php the_post_thumbnail_url('card-white');?>);"></div>
<div>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php if (get_post_type() === 'post') { get_template_part('templates/entry-meta'); } ?>
<?php if ( has_excerpt() ) {?>
<p><?php echo get_the_excerpt(); ?></p>
<?php } //end if ?>
</div>
</article>