在需要调用类别的地方,比如列表页,首先写循环前面写上一句:
<?php $TYPE = getcache(‘type_content’,’commons’);?>
这句就是把类别缓存加载进来.
然后在循环里写:
<a href=”index.php?m=content&c=type&catid={$catid}&typeid={$r[typeid]}”>{$TYPE[$r[typeid]][name]}</a>
这样就可以调用出来类别了.
不过链接暂时无效.因为还没有做好链接文件.后面会更新这个文件的.
类别链接页面:
新增一个 type.html 文件放到 phpcms\templates\default\content\ 下:
该文件代码如下:
- {template “content”,”header”}
- <!–main–><?php $typeid = intval($_GET[‘typeid’]);?>
- <div class=”main”>
- <div class=”col-left”>
-
<div class=”crumbs”><a href=”{siteurl($siteid)}”>塘下网首页</a><span> > </span>{catpos($catid)} 类别:<font color=”red”>{$TYPE[$typeid][name]}</font> 总共有 {$total} 条记录</div> -
<ul class=”list lh24 f14″> - {loop $datas $r}
- <li><span class=”rt”>{date(‘Y-m-d H:i:s’,$r[inputtime])}</span>·<a href=”{$r[url]}” target=”_blank”{title_style($r[style])}>{$r[title]}</a></li>
- {if $n%5==0}<li class=”bk20 hr”></li>{/if}
- {/loop}
-
</ul> -
<div id=”pages” class=”text-c”>{$pages}</div> -
</div> -
<div class=”col-auto”> -
<div class=”box”> -
<h5 class=”title-2″>频道总排行</h5> -
{pc:content action=”hits” catid=”$catid” num=”10″ order=”views DESC”} -
<ul class=”content digg”> -
{loop $data $r} -
<li><a href=”{$r[url]}” target=”_blank”>{$r[title]}</a></li> -
{/loop} -
</ul> -
{/pc} -
</div> -
-
</div> - </div>
- {template “content”,”footer”}
新增一个 type.php 文件到 phpcms\modules\content\下,该文件代码如下:
- <?php
- defined(‘IN_PHPCMS’) or exit(‘No permission resources.’);
- //模型缓存路径
- define(‘CACHE_MODEL_PATH’,CACHE_PATH.’caches_model’.DIRECTORY_SEPARATOR.’caches_data’.DIRECTORY_SEPARATOR);
- pc_base::load_app_func(‘util’,’content’);
- class type {
- private $db;
- function __construct() {
-
$this->db = pc_base::load_model(‘content_model’); - }
- public function init() {
-
if(!isset($_GET[‘catid’])) showmessage(L(‘missing_part_parameters’)); -
$catid = intval($_GET[‘catid’]); -
$siteids = getcache(‘category_content’,’commons’); -
$siteid = $siteids[$catid]; -
$this->categorys = getcache(‘category_content_’.$siteid,’commons’); -
if(!isset($this->categorys[$catid])) showmessage(L(‘missing_part_parameters’)); -
if(isset($_GET[‘info’][‘catid’]) && $_GET[‘info’][‘catid’]) { -
$catid = intval($_GET[‘info’][‘catid’]); -
} else { -
$_GET[‘info’][‘catid’] = 0; -
} -
if(isset($_GET[‘typeid’]) && trim($_GET[‘typeid’]) != ”) { -
$typeid = intval($_GET[‘typeid’]); -
} else { -
showmessage(L(‘illegal_operation’)); -
} -
$TYPE = getcache(‘type_content’,’commons’); -
$modelid = $this->categorys[$catid][‘modelid’]; -
$modelid = intval($modelid); -
if(!$modelid) showmessage(L(‘illegal_parameters’)); -
$CATEGORYS = $this->categorys; -
$siteid = $this->categorys[$catid][‘siteid’]; -
$siteurl = siteurl($siteid); -
$this->db->set_model($modelid); -
$page = $_GET[‘page’]; -
$datas = $infos = array(); -
$infos = $this->db->listinfo(“`typeid` = ‘$typeid'”,’id DESC’,$page,20);//读取整个模型下同类别文章 -
//$infos = $this->db->listinfo(“`typeid` = ‘$typeid’ AND catid = ‘$catid'”,’id DESC’,$page,20);//仅仅读取当前栏目下的同类别文章,如果要启用此模式,请去掉上一行代码并将本行开头的// 两斜杠去掉. -
$total = $this->db->number; -
if($total>0) { -
$pages = $this->db->pages; -
foreach($infos as $_v) { -
if(strpos($_v[‘url’],’://’)===false) $_v[‘url’] = $siteurl.$_v[‘url’]; -
$datas[] = $_v; -
} -
} -
$SEO = seo($siteid, $catid, $TYPE[$typeid][‘name’],$TYPE[$typeid][‘description’],$TYPE[$typeid][‘name’].’类别’); -
include template(‘content’,’type’); - }
- }
- ?>
上面的链接即可生效.
需要注意的是: