«

非插件实现Emlog时间轴归档代码分享

时间:2015-8-2 15:17     作者:admin     分类: emlog


文件缓存型时间轴归档,后台更新缓存或者发布新文章的时候会自动更新;本站这个代码是使用缓存系统的,是需要修改内核文件的。慎用!

1、修改include/lib/cache.php文件,添加归档缓存函数


<pre style="overflow:auto" ;class="prettyprint lang-php linenums">private $logalias_cache;
之后添加
private $loglists_cache;

添加在其他缓存函数位置添加归档缓存


<pre style="overflow:auto" ;class="prettyprint lang-php linenums"> /** 文章归档列表缓存 /
private function mc_loglists() {
$query = $this->db->query('select gid,title,date from ' . DB_PREFIX . "blog WHERE hide='n' and checked='y' and type='blog' ORDER BY date DESC");
$loglists_cache = array();
while ($row = $this->db->fetch_array($query)) {
$loglists_cache[]= $row;
}
$cacheData = serialize($loglists_cache);
$this->cacheWrite($cacheData, 'loglists');
}
不懂的朋友只请直接下载本文件覆盖include/lib/cache.php(请做好备份)cache.zip

2、此方法因不同的模板修改的有所差异,本站讲述以默认模板为例,首先复制模板目录下的page.php并重新命名为guidang.php(ps:这个自己可自行修改),把其中的<?php echo $log_content; ?>更改为如下代码即可



<pre style="overflow:auto" ;class="prettyprint lang-php linenums"><div class="guidang">
<?php
global $CACHE;
$loglists_cache = $CACHE->readCache('loglists');
$year_month = 0;
foreach($loglists_cache as $value):
if($year_month != 0&&$year_month != date("Y-m",$value['date'])){
echo '</ul>';}
if($year_month != date("Y-m",$value['date'])){
$year_month = date("Y-m",$value['date']);
echo '<h2 class="guidang-tt">'.$year_month.'</h3><ul>';}
?>
<li><a href="<?php echo Url::log($value['gid']);?>" target="_blank" title="<?php echo $value['title']; ?>"><span><?php echo date("Y-m-d",$value['date']);?></span><div class="atitle"><?php echo $value['title'];?></div></a></li>
<?php endforeach;?></div>
css文件如下



<pre style="overflow:auto" ;class="prettyprint lang-css linenums">.guidang h2{font-size:150%;}
.guidang li a{padding:8px 0;display:block}
.guidang li a:hover .atitle:after{background:#ff5c43}
.guidang li a span{display: inline-block;width:100px;font-size:12px;text-indent:20px}
.guidang li a .atitle{display: inline-block;padding:0 15px;position:relative;width:550px;white-space:nowrap;text-overflow:ellipsis;}
.guidang li a .atitle:after{position:absolute;left:-2px;background:#ccc;height:8px;width:8px;border-radius:6px;top:8px;content:""}
.guidang li a .atitle:before{position:absolute;left:-4px;background:#fff;height:12px;width:12px;border-radius:6px;top:6px;content:""}
.guidang{margin:10px;position:relative;padding:10px 0}
.guidang:before{height:100%;width:4px;background:#eee;position:absolute;left:100px;content:"";top:0}
.guidang-tt{position:relative;margin:10px 0;cursor:pointer}
.guidang-tt:hover:after{background:#ff5c43}
.guidang-tt:before{position:absolute;left:93px;background:#fff;height:18px;width:18px;border-radius:6px;top:3px;content:""}
.guidang-tt:after{position:absolute;left:96px;background:#ccc;height:12px;width:12px;border-radius:6px;top:6px;content:""}


然后建立一个页面,在页面模板处填写 guidang 即可,演示地址:https://mrxn.net/guidang.html



标签: emlog

版权所有:Mrxn's Blog
文章标题:非插件实现Emlog时间轴归档代码分享
除非注明,文章均为 Mrxn's Blog 原创,请勿用于任何商业用途,转载请注明作者和出处 Mrxn's Blog

扫描二维码,在手机上阅读

推荐阅读: