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博客搜索关键词高亮显示实现代码》的一些看法。更多内容请查看本栏目更多内容!
判别置顶文章 is_sticky() 函数用来判别一篇文章能否为置顶文章。 用法 is_sticky( $post_id ); 参数 $p...
链接方式http://localhost/?go=http://www.baidu.com这种方式转跳的办法。 复制代码代码如下:add_action('w...
在WordPress中,咱们发如今写文章时,可视化模式下会对html代码进行清算,例如对<>等符号转化为html实体,对...
关于有的主题,当从后盾小工具中增加友谊链接后,却发现其是为全站显示的。假如只心愿让它在首页显示,则能...
处理方法: 办法一: 修正文件“/wp-includes/pluggable.php”中的wp_set_auth_cookie函数。搜寻...
复制代码代码如下: //该办法为向曾经存在的菜单中增加子菜单 function add_submenu() { add_submenu_page( ...