在搜索结果中,我想添加一个按钮“找不到运动鞋?单击此处”。该按钮将作为到另一个页面的链接,客户可以在该页面上提交自定义订单。请告诉我该按钮的编码位置。
我尝试在search.php中添加按钮代码,但按钮未出现在搜索结果页面中
”
<?php if ( $postCount > 8 ) { ?>
<div class="row">
<div class="col-sm-12">
<div class="search-form-wrapper u-mb-30">
<div class="search gensearch__wrapper kl-gensearch--<?php echo zget_option( 'zn_main_style', 'color_options', false, 'light' ); ?>">
<?php get_search_form(); ?>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<div class="row">
<div class="col-sm-12">
<a class="btn" href="">Not found Desired Sneakers? Click here</a>
</div>
</div>
</section>
”
答案 0 :(得分:0)
假设您使用的是默认的WordPress搜索页面,则可以通过全局wp_query访问结果数。
global $wp_query;
$customOrderPageId = 10; // UPDATE with your custom order page ID
$searchTerm = get_search_query() // If you want a flexible "Desired Sneakers" based on what the user is searching...
if ($wp_query->found_posts == 0) {
echo '<a class="btn" href="'.get_permalink($customOrderPageId).'">Not found '.$searchTerm.'? Click here</a>';
}