主题选择页面增加搜索功能
09月 10th, 2008 by brian | No Comments | Filed in WordPress, WordPress mu主题多的时候,挑选主题很麻烦,特别是想要的主题不在第一页的时候,得一页一页的去翻。
搞定wpmu-themes.php 的主题批量激活JS后轮到给 themes.php 动手术了。
1. /wp-admin/themes.php 19行,两个reset( $themes ) 之间的内容改为以下,目的是搜索符合的主题:
reset( $themes );
$theme_all=count($themes); //add by libanglai 20080910
foreach( $themes as $key => $theme ) {
if( isset( $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == false ) {
unset( $themes[ $key ] );
}
//add by libanglai 20080910 start
else if( isset($_GET['search']) ) {
$str=$themes[ $key ][Name].’,’.$themes[ $key ][Title].’,’.$themes[ $key ][Description].’,’.$themes[ $key ][Author];
$str.=implode(’,',$themes[ $key ]['Tags']);
$str=strtolower($str);
//echo $str.”|”; //for debug
//echo strpos($str,strtolower($_GET['search'])).”<br>”; //for debug
if(strpos($str,strtolower($_GET['search']))===false ){
unset( $themes[ $key ] );
}
}
//end add by libanglai 20080910
}
reset( $themes );
$theme_show=count($themes); //add by libanglai 20080910
2. 62行 <?php if ( ! validate_current_theme() ) : ?> 之前加入以下内容,目的是加上搜索框
<!–for search themes, add by libanglai //–>
<form action=’themes.php’ method=’get’ name=’form1′>
<div id=”message0″ class=”updated fade”><p><?php _e(’SEARCH THEMES: You can enter a word to search for the themes that name,description or tags include this word.’); ?>
<input type=input name=’search’ value=’<?php echo $_GET['search'];?>’><input type=submit value=”<?php _e(”Search”); ?>”>
</p></div>
</form>
<!– end //—>
3. 128行要改一下,否则搜索结果只有1个时不会显示
<?php if ( 1 < $theme_total ) { ?>
改为:
<?php if ( 1 <= $theme_total ) {//edit by libanglai 20080910 ?>
4. 117行改一下,让它显示搜索结果数和主题总数:
<h2><?php _e(’Available Themes’); ?></h2>
改为:
<h2><?php _e(’Available Themes’); echo “  ”.$theme_show.’ of ‘.$theme_all;//add for show num of search result ?></h2>
修改四个地方,都没动到wordpress原有的代码,手术还不算大,和效果很不错啊,看下面的图:
