⎠⎞MH-Studio⎠⎞ ⎠⎞MH-Studio⎠⎞
  • 首页
  • 我的开发
  • 资源分享
    • 软件程序
    • 手机APP
    • 学习课程
    • 建站源码
    • 其他资源
  • 工具中心
    • 创意工具
    • 效率工具
    • 辅助插件
    • 导航合集
  • 技术资讯
    • 技术应用
    • 福利线报
  • 闲言碎语
  • 首页
  • 我的开发
  • 资源分享
    • 软件程序
    • 手机APP
    • 学习课程
    • 建站源码
    • 其他资源
  • 工具中心
    • 创意工具
    • 效率工具
    • 辅助插件
    • 导航合集
  • 技术资讯
    • 技术应用
    • 福利线报
  • 闲言碎语
  • VIP视频
网站首页 › 技术资讯 › Emlog 按字母排序的标签页源码
#PHP #网站 #Emlog

Emlog 按字母排序的标签页源码

8年前 (2015-01-21)
41519 0 0

接触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*/





0 0 赞赏
Mengx
相关文章
怎么追回在微信上被骗的钱?试试这招
2020年支付宝集五福隐藏福卡
免资料开通支付宝当面付
淘宝双十一合伙人店铺自动签到得喵币方法
抖音企业认证限免活动,立省600元
评论 (0)
再想想
凣高先生 博主
求知若饥,虚心若愚。[Stay Hungry, Stay Foolish.]
177 文章 726 评论 35 微语
最新文章
PC朋友圈数据采集工具[V1.0.4](2022.12.11)
5个月前 (10-19)
关于PC微信朋友圈信息的自动采集
1年前 (2022-01-12)
最新手机通过微信wxid加微信好友教程
2年前 (2021-09-06)
微博批量采集下载工具[V1.0.9](2023.01.01)
2年前 (2021-06-01)
微商相册批量转发下载工具[V1.7.2](2022.07.03)
2年前 (2021-03-28)
热门文章
软件APP蓝奏云网盘更新下载合集
朋友圈采集备份工具[V4.0.4](2022.08.26)
磁力链接BT种子电驴搜索下载网站合集
推荐|俄罗斯无限制搜索引擎——Yandex
漫画APP网站在线观看合集
  • 博文专题
  • |
  • 文章归档
  • |
  • 标签页面
  • |
  • 关于博主
  • |
  • 留言板
  • |
  • 友情链接
Copyright © 2020 ⎠⎞MH-Studio⎠⎞. Designed by MH-Studio. | 站点地图 | 粤ICP备14091663号-1 | Sitemap |