Relevanssi - 记录重复搜索
Relevanssi - Duplicate Searches logged
我正在使用(并且喜欢)WordPress 的 Relevanssi 插件。虽然搜索在用户搜索中被记录两次,但遇到问题。
Found this comment in the plugin comments about it being a problem with the template.
在搜索我的搜索模板时,我只是删除了所有内容,然后零碎地添加内容,直到我再次获得双重结果。
我的搜索模板中的这一行似乎是麻烦制造者,但我不一定明白为什么。
<div style="background-image: url();"></div>
这对我来说意义为 0。如果 STATIC html 的那个位在 content-search.php
模板中,我会记录双重搜索。如果我删除它,或者如果所有文章都有 get_the_post_thumbnail_url
,那么我只会记录一次搜索。
好像和style="background-image:url();"
没有值有关系?
这是大图:
search.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 ?>
内容-search.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>
我重新安装了 Wordpress,并用 2017 年的主题测试了这个奇怪的理论。确实如此,如果我将 <div style="background-image:url();"></div>
添加到模板 template-parts/post/content-excerpt.php
,则会记录重复搜索。
如果 div 有图像:<div style="background-image:url(http://image.com);"></div>
只记录一次搜索。
至少对此有一个解释当然很好。
在将内联样式呈现到页面之前,我只需检查一下是否有 bkgd 图像就可以防止这种情况发生,现在我知道在未来!
$style = ! empty( get_the_post_thumbnail_url($the_post, 'card-white') ) ?
'style="background-image: url(' . get_the_post_thumbnail_url($the_post, 'card-white') . ');"' : '';
<div class="article-card__img" <?php echo $style; ?>></div>
我正在使用(并且喜欢)WordPress 的 Relevanssi 插件。虽然搜索在用户搜索中被记录两次,但遇到问题。
Found this comment in the plugin comments about it being a problem with the template.
在搜索我的搜索模板时,我只是删除了所有内容,然后零碎地添加内容,直到我再次获得双重结果。
我的搜索模板中的这一行似乎是麻烦制造者,但我不一定明白为什么。
<div style="background-image: url();"></div>
这对我来说意义为 0。如果 STATIC html 的那个位在 content-search.php
模板中,我会记录双重搜索。如果我删除它,或者如果所有文章都有 get_the_post_thumbnail_url
,那么我只会记录一次搜索。
好像和style="background-image:url();"
没有值有关系?
这是大图:
search.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 ?>
内容-search.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>
我重新安装了 Wordpress,并用 2017 年的主题测试了这个奇怪的理论。确实如此,如果我将 <div style="background-image:url();"></div>
添加到模板 template-parts/post/content-excerpt.php
,则会记录重复搜索。
如果 div 有图像:<div style="background-image:url(http://image.com);"></div>
只记录一次搜索。
至少对此有一个解释当然很好。
在将内联样式呈现到页面之前,我只需检查一下是否有 bkgd 图像就可以防止这种情况发生,现在我知道在未来!
$style = ! empty( get_the_post_thumbnail_url($the_post, 'card-white') ) ?
'style="background-image: url(' . get_the_post_thumbnail_url($the_post, 'card-white') . ');"' : '';
<div class="article-card__img" <?php echo $style; ?>></div>