function hls_set_query() {
$query = attribute_escape(get_search_query());
if(strlen($query) > 0){
echo '
<script type="text/javascript">
var hls_query = "'.$query.'";
</script>
';
}
}
function hls_init_jquery() {
wp_enqueue_script('jquery');
}
add_action('init', 'hls_init_jquery');
add_action('wp_print_scripts', 'hls_set_query'); 而后把上面的代码放在header.php中,就OK了。
<style type="text/css" media="screen">
.hls { background: #D3E18A; }
</style>
<script type="text/javascript">
jQuery.fn.extend({
highlight: function(search, insensitive, hls_class){
var regex = new RegExp("(<[^>]*>)|(b"+ search.replace(/([-.*+?^${}()|[]/])/g,"$1") +")", insensitive ? "ig" : "g");
return this.html(this.html().replace(regex, function(a, b, c){
return (a.charAt(0) == "<") ? a : "<strong class=""+ hls_class +"">" + c + "</strong>";
}));
}
});
jQuery(document).ready(function($){
if(typeof(hls_query) != 'undefined'){
$("#post-area").highlight(hls_query, 1, "hls");
}
});
</script>
以上就是安达网络工作室关于《wordpress博客搜索关键词高亮显示实现代码》的一些看法。更多内容请查看本栏目更多内容!
要害字形容:应用 插件 Wordpress 能够 文件 需求 网站 目录 网友 Wordpress 的主题能够让你的 Wordpress ...
废话不多说,间接上代码复制代码代码如下:<?phprequire('./wp-blog-header.php');header("Content-type: te...
前言 家喻户晓WordPress默许支持大局部图片等文件格局的上传,但也有一些文件格局是不支持的,依据集体需求...
最近我心血来潮给博客建一个分类别名为“WordPress”的目录。可是不断提醒“别名已被其它条...
本文实例讲述了WordPress应用RSS Feed输入自定义文章类型内容的办法。分享给大家供大家参考。详细剖析如下:...
【阐明】 反省以后文章能否置顶。前往值TRUE 或许 FALSE. 【用法】 复制代码代码如下:<?php is_sticky($pos...