接触emlog也快一个月了,不敢说已经完全掌握,但还算了解吧,也可以自己摸索一些功能。
熟悉wordpress的都知道,wordpress有各种漂亮的标签页,而emlog,搜索了下,找到一些,看起来很是简单,都是直接调用emlog的全局缓存变量里的直接foreach输出,和emlog边栏的标签没什么两样,于是就自己移植了wordpress的。
效果:点击查看
代码如下:
首先,要修改的是主题文件夹下的module.php文件,在里面添加一下代码:
//根据标题首字母输出标签页面{ //输出标签 function specs_show_tags() { global $CACHE; $tag_cache = $CACHE->readCache('tags'); foreach($tag_cache as $value){ for($i = 65; $i <= 90; $i++){ if(specs_pinyin($value['tagname']) == chr($i)){ $r[chr($i)][] = $value; } } for($i=48;$i<=57;$i++){ if(specs_pinyin($value['tagname']) == chr($i)){ $r[chr($i)][] = $value; } } } ksort($r); $output = "<ul id='tag-letter'>"; for($i=65;$i<=90;$i++){ $tagi = $r[chr($i)]; if(is_array($tagi)){ $output .= "<li><a href='#".chr($i)."'>".chr($i)."</a></li>"; }else{ $output .= "<li><a class='none' href='javascript:;'>".chr($i)."</a></li>"; } } for($i=48;$i<=57;$i++){ $tagi = $r[chr($i)]; if(is_array($tagi)){ $output .= "<li><a href='#".chr($i)."'>".chr($i)."</a></li>"; }else{ $output .= "<li><a class='none' href='javascript:;'>".chr($i)."</a></li>"; } } $output .= "</ul>"; $output .= "<ul id='all-tags'>"; for($i=65;$i<=90;$i++){ $tagi = $r[chr($i)]; // print_r($tagi); if(is_array($tagi)){ $output .= "<li id='".chr($i)."'><h4 class='tag_name'>".chr($i)."</h4><div class='tag-list clearfix'>"; foreach($tagi as $tag){ $output .= "<a href='".Url::tag($tag['tagurl'])."'>".$tag['tagname']."<span class='number'>(".$tag['usenum'].")</span></a>"; } $output .= "</div></li>"; } } // echo $output; for($i=48;$i<=57;$i++){ $tagi = $r[chr($i)]; if(is_array($tagi)){ $output .= "<li id='".chr($i)."'><h4 class='tag_name'>".chr($i)."</h4><div class='tag-list clearfix'>"; foreach($tagi as $tag){ $output .= "<a href='".Url::tag($tag['tagurl'])."'>".$tag['tagname']."<span class='number'>(".$tag['usenum'].")</span></a></div>"; } $output .= "</div></li>"; } } $output .= "</ul>"; echo $output; } //PHP获取汉字拼音首字母 function specs_getfirstchar($s0){ $fchar = ord($s0{0}); if($fchar >= ord("A") and $fchar <= ord("z") )return strtoupper($s0{0}); $s1 = iconv("UTF-8","gb2312", $s0); $s2 = iconv("gb2312","UTF-8", $s1); if($s2 == $s0){$s = $s1;}else{$s = $s0;} $asc = ord($s{0}) * 256 + ord($s{1}) - 65536; if($asc >= -20319 and $asc <= -20284) return "A"; if($asc >= -20283 and $asc <= -19776) return "B"; if($asc >= -19775 and $asc <= -19219) return "C"; if($asc >= -19218 and $asc <= -18711) return "D"; if($asc >= -18710 and $asc <= -18527) return "E"; if($asc >= -18526 and $asc <= -18240) return "F"; if($asc >= -18239 and $asc <= -17923) return "G"; if($asc >= -17922 and $asc <= -17418) return "H"; if($asc >= -17417 and $asc <= -16475) return "J"; if($asc >= -16474 and $asc <= -16213) return "K"; if($asc >= -16212 and $asc <= -15641) return "L"; if($asc >= -15640 and $asc <= -15166) return "M"; if($asc >= -15165 and $asc <= -14923) return "N"; if($asc >= -14922 and $asc <= -14915) return "O"; if($asc >= -14914 and $asc <= -14631) return "P"; if($asc >= -14630 and $asc <= -14150) return "Q"; if($asc >= -14149 and $asc <= -14091) return "R"; if($asc >= -14090 and $asc <= -13319) return "S"; if($asc >= -13318 and $asc <= -12839) return "T"; if($asc >= -12838 and $asc <= -12557) return "W"; if($asc >= -12556 and $asc <= -11848) return "X"; if($asc >= -11847 and $asc <= -11056) return "Y"; if($asc >= -11055 and $asc <= -10247) return "Z"; return null; } function specs_pinyin($zh){ $ret = ""; $s1 = iconv("UTF-8","gb2312", $zh); $s2 = iconv("gb2312","UTF-8", $s1); if($s2 == $zh){$zh = $s1;} $s1 = substr($zh,$i,1); $p = ord($s1); if($p > 160){ $s2 = substr($zh,$i++,2); $ret .= specs_getfirstchar($s2); }else{ $ret .= $s1; } return strtoupper($ret); } //标签页end }之后,在主题文件夹中新建一个名为tag.php文件,复制page.php的内容粘贴进去,把里面的:
<?php echo $log_content; ?> <?php blog_comments($comments); ?> <?php blog_comments_post($logid,$ckname,$ckmail,$ckurl,$verifyCode,$allow_remark); ?>替换成
<div class="tags-page"><?php specs_show_tags(); ?></div>保存
最后,新建个页面,模板和别名都填上tags,就可以了,访问:http://你的域名/tags,就可以看到内容,但是,没用样式啊,那在此我提供我博客的通用样式吧!把我的样式复制到主题文件夹下的css文件就可以了,需要改成怎样的这个需要大家自己发挥了
/*tags*/ #tag-letter{padding: 0 15px} #tag-letter li{display: inline-block;margin: 10px} #tag-letter li a{border: 1px solid #ee9285;color: #ee9285;padding: 5px 6px;text-align: center;width: 20px;display: inline-block;-webkit-transition: all .3s ease-in-out;transition: all .3s ease-in-out} #tag-letter li a:not(.none):hover{border: 1px solid #ee9285;color: #fff;background-color: #ee9285} #tag-letter li .none{background-color: #fafafa;border: 1px solid #EEE;color: #DDD;cursor: not-allowed} #all-tags li{margin: 20px 35px} #all-tags li:last-child .tag-list{border-bottom: 0} #all-tags .tag-name{font-size: 1.8rem} #all-tags .tag-list{margin:0 30px;padding-bottom:20px;border-bottom: 1px dotted #ee9285;} #all-tags .tag-list a{color: #333;padding: 2px 8px;float: left;} #all-tags .tag-list a:hover{color:#ee9285} #all-tags .tag-list a .number{font-size: .8rem;position: relative;top: -6px;margin-left: 5px} .clearfix:before, .clearfix:after {content: "";display: table;} .clearfix:after {clear: both;} /*tags*/