dedecms织梦文章按年月日进行归档效果图:
思路
从文档表中取得年,月,日的归档文档,按年或月或日输出。
前端代码
<divclass="newbody"> <!--代码开始--> <divclass="head-warp"> <divclass="head"> <divclass="nav-box"> <ul> <liclass="cur"style="text-align:center;font-size:22px;font-family:'微软雅黑','宋体';">文章归档</li> </ul> </div> </div> </div> <divclass="main"> <divclass="history"> {dede:arclist2row=12format=mtime=pubdate} <divclass="history-date"> <ul> <h2class="first"><arel="nofollow noopener noreferrer" href="#nogo">[field:datefunction=MyDate('Y年m月',strtotime(@me))/]</a></h2> [field:daterunphp="yes"] global$dsql; $startTime=strtotime(@me.'-01'); $endTime=strtotime('+1month',$startTime); $qtypeQuery="WHEREarc.arcrank>=0andarc.pubdatebetween$startTimeAND$endTimeORDERBYarc.iddesclimit10"; $sql="SELECTarc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart, tp.moresite,tp.siteurl,tp.sitepathFROM`blog_archives`arcleftjoin`blog_arctype`tponarc.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='<fontcolor="#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><arel="nofollow noopener noreferrer" 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、\include\taglib\arclist2.lib.php
<?phpif(!defined('DEDEINC'))exit('RequestError!'); /** *文章归档标签 * *@packageDedeCMS.Dedediy *@copyrightCopyright(c)2013-2016 *@linkhttp://www.dedediy.com */ functionlib_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=newDedeTagParse(); $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="selectFROM_UNIXTIME($time,'$format2')ASdate,count(*)AScountFROM`blog_archives`$qtypeQuerygroupbydateorderbydatedesclimit$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->CTagsas$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
到此这篇关于dedecms织梦文章按年月日进行归档就介绍到这了。为了以后能随时偷懒,现在就得时刻努力。更多相关dedecms织梦文章按年月日进行归档内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!