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博客搜索关键词高亮显示实现代码》的一些看法。更多内容请查看本栏目更多内容!
办法一,用filter发送HTML邮件 发邮件用的函数是wp_mail(),wp_mail()则基于弱小的邮件类phpMailer,所以发...
就在discuz地图插件公布后不久,百度终于面向世界上最驰名的WordPress公布了地图插件!援用百度民间的引见,...
WordPress模板根本文件 复制代码代码如下:style.css 款式表文件index.php 主页文件single.php 日志单页文件...
我网上找了很多处理导航计划的成绩,均无奈用于WordPress3.1之上,总会呈现其余成绩。而我所解说的这种办法...
本文实例讲述了Wordpress主动将蕴含长链接的评论标志为渣滓评论的办法。分享给大家供大家参考。详细剖析如下...
咱们先来看一下什么是nofollow。NoFollow是Google几年前提出的一个新标签,目的是缩小渣滓留言。此标签标明...