今天进行技术分享的为Fans,精彩分享内容如下:
@fans 主要分享了通过往functions.php里加入如下代码实现WordPress自带的搜索里边高亮显示搜索词:
function search_word_replace($buffer){ if(is_search()){ $arr = explode(" ", get_search_query()); $arr = array_unique($arr); foreach($arr as $v) if($v) $buffer = preg_replace("/(".$v.")/i", "<span class=\"key-search-word\">$1</span>", $buffer); } return $buffer; } add_filter("the_title", "search_word_replace", 200); add_filter("the_excerpt", "search_word_replace", 200); add_filter("the_content", "search_word_replace", 200);
通过加入如下代码实现自适应的TAB切换效果:
<script src="<?php bloginfo('template_url')?>/js/responsive-tabs.js"></script> <script type="text/javascript"> $( ' ul.nav.nav-tabs a' ).click( function ( e ) { e.preventDefault(); $( this ).tab( 'show' ); } ); (function($) { fakewaffle.responsiveTabs(['xs', 'sm']); })(jQuery); </script>
通过加入如下代码,实现自定义分页效果:
function custom_posts_per_page($query){ if(is_search()){ $query->set('posts_per_page',20); } if( $query->is_main_query() && !is_admin() && is_archive( 'induction_video_category' ) ) { $query->set( 'posts_per_page', '15' ); } } add_action('pre_get_posts','custom_posts_per_page');