dedecms织梦文章按年月日进行归档效果图:
(此图片来源于网络,如有侵权,请联系删除! )
思路
从文档表中取得年,月,日的归档文档,按年或月或日输出。
前端代码
<div class="newbody"> <!-- 代码 开始 --> <div class="head-warp"> <div class="head"> <div class="nav-box"> <ul> <li class="cur" style="text-align:center; font-size:22px; font-family:'微软雅黑', '宋体';">文章归档</li> </ul> </div> </div> </div> <div class="main"> <div class="history"> {dede:arclist2 row=12 format=m time=pubdate} <div class="history-date"> <ul> <h2 class="first"><a href="#nogo">[field:date function=MyDate('Y年m月',strtotime(@me))/]</a></h2> [field:date runphp="yes"] global $dsql; $startTime = strtotime(@me.'-01'); $endTime = strtotime('+1 month',$startTime); $qtypeQuery = " WHERE arc.arcrank>=0 and arc.pubdate between $startTime AND $endTime ORDER BY arc.id desc limit 10"; $sql = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart, tp.moresite,tp.siteurl,tp.sitepath FROM `blog_archives` arc left join `blog_arctype` tp on arc.typeid=tp.id $qtypeQuery"; $dsql->SetQuery($sql); $dsql->Execute('t'); $result = ''; while($row = $dsql->GetArray('t')) { $arcurl = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],$row['arcrank'], $row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']); if(date("m-d",$row['pubdate'])==date("m-d")){ $pubdate = '<font color="#FF0000">'.MyDate('m-d',$row['pubdate']).'</font>'; } else { $pubdate = MyDate('m-d',$row['pubdate']); } $description = cn_substr($row['description'],100); $result .= <<< TPL <li> <h3>{$pubdate}</h3> <dl> <dt><a href="{$arcurl}" target="_blank">{$row['title']}</a> <span>{$description}</span> </dt> </dl> </li> TPL; } @me = $result; [/field:date] </ul> </div> {/dede:arclist2} </div> </div> </div>
1、includetaglibarclist2.lib.php
<?php if(!defined('DEDEINC')) exit('Request Error!'); /** * 文章归档标签 * * @package DedeCMS.Dedediy * @copyright Copyright (c) 2013 - 2016 * @link http://www.dedediy.com */ function lib_arclist2(&$ctag,&$refObj) { global $dsql; //属性处理 $attlist="format|y,start|,end|,time|pubdate,row|10"; FillAttsDefault($ctag->CAttribute->Items,$attlist); extract($ctag->CAttribute->Items, EXTR_SKIP); $line = empty($row) ? 10 : $row; $innertext = $ctag->GetInnerText(); if(trim($innertext)=='') $innertext = GetSysTemplets("arclist2.htm"); switch ($format) { case 'y': $format2 = '%Y'; break; case 'm': $format2 = '%Y-%m'; break;; case 'd': $format2 = '%Y-%m-%d'; break; default: $format2 = '%Y-%m-%d'; } $ctp = new DedeTagParse(); $ctp->SetNameSpace('field', '[', ']'); if(!empty($start)) { $qtypeQuery = ' WHERE '.$time.'>'.strtotime($start); } if(!empty($end)){ $qtypeQuery .= $qtypeQuery ? ' AND '.$time.'<'.strtotime($end) : ' WHERE '.$time.'<'.strtotime($end); } $solvingask = ''; $query = "select FROM_UNIXTIME($time, '$format2') AS date,count(*) AS count FROM `blog_archives` $qtypeQuery group by date order by date desc limit $line"; $dsql->Execute('me',$query); while($rs = $dsql->GetArray('me')) { $ctp->LoadSource($innertext); if($rs['date']) { $rs['dateurl'] = '/plus/arcDate.php?time='.$time.'&date='.$rs['date'].'&format='.$format; foreach($ctp->CTags as $tagid=>$ctag) { if(!empty($rs[strtolower($ctag->GetName())])) { $ctp->Assign($tagid,$rs[$ctag->GetName()]); } } $solvingask .= $ctp->GetResult(); } } return $solvingask; }
更多归档文件打包
链接: http://pan.baidu.com/s/1jIr4V0i 密码: jy3e
© 版权声明
THE END
暂无评论内容