通过搜索框去搜索品牌商跳转到指定网址。
实现步骤:
搜索框搜索:品牌名称
基于 WP 和 Page Links To 插件
创建独立页面 WP 新建独立页面
独立页面:http://cpuck.com/deli
独立页面跳转到新建单独网页
添加搜索跳转代码
单独页面:http://cpuck.com/deli.html
WP 配置文件代码:functions.php
//当搜索结果只有一条直接跳转
add_action('template_redirect', 'redirect_single_post');
function redirect_single_post() {
if (is_search()) {
global $wp_query;
if ($wp_query->post_count == 1 && $wp_query->max_num_pages == 1) {
wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
exit;
}
else if ($wp_query->post_count == 0 && $wp_query->max_num_pages == 0) {
header('Location:/404');
exit;
}
}
}
//提高搜索结果相关性
if(is_search()){
add_filter('posts_orderby_request', 'search_orderby_filter');
}
function search_orderby_filter($orderby = ''){
global $wpdb;
$keyword = $wpdb->prepare($_REQUEST['s']);
return "((CASE WHEN {$wpdb->posts}.post_title LIKE '%{$keyword}%' THEN 2 ELSE 0 END) + (CASE WHEN {$wpdb->posts}.post_content LIKE '%{$keyword}%' THEN 1 ELSE 0 END)) DESC,
{$wpdb->posts}.post_modified DESC, {$wpdb->posts}.ID ASC";
}
搜索跳转代码:
<script type="text/javascript">
var ua = navigator.userAgent.toLowerCase();
var isWeixin = ua.indexOf('micromessenger') != -1;
var isAndroid = ua.indexOf('android') != -1;
var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);
if (isWeixin) {
document.location.href= 'https://u.jd.com/0Bo2lJ';
}
</script>
<script language='javascript'>
function test(){
var url=new Array();
url[0]='https://s.click.taobao.com/t?e=m%3D2%26s%3D%2BEl3Gv%2B3yI8cQipKwQzePDAVflQIoZepK7Vc7tFgwiFRAdhuF14FMR9GFBL0cYtQMMgx22UI05aWq%2FexghClVT9EgWwlZwxaRkuHStOcAWCnibXl54%2Fvr2vh6ZUsBYPPup2liYv1HSvGJe8N%2FwNpGw%3D%3D';
var ints=parseInt(Math.random()*(url.length));
window.location=url[ints];
url[1]='http://www.nbdeli.com/';
var ints=parseInt(Math.random()*(url.length));
window.location=url[ints];
}
</script>
<script type='text/javascript'>var _url = 'http://'+test()+'/';</script>
最终实现结果:非微信端搜索品牌名称跳转到天猫或官网,微信端搜索跳转到品牌京东店铺。
相关链接:自然语言