在需要调用类别的地方,比如列表页,首先写循环前面写上一句:

<?php $TYPE = getcache('type_content','commons');?>

这句就是把类别缓存加载进来.

然后在循环里写:

<a href="index.php?m=content&c=type&catid={$catid}&typeid={$r[typeid]}">{$TYPE[$r[typeid]][name]}</a>
这样就可以调用出来类别了.

不过链接暂时无效.因为还没有做好链接文件.后面会更新这个文件的.

更新时间: 2011年1月3日1:12:01
类别链接页面:
新增一个 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');
}
}
?>

上面的链接即可生效.
需要注意的是:
  $infos = $this->db->listinfo("`typeid` = '$typeid'",'id DESC',$page,20);//读取整个模型下同类别文章
  //$infos = $this->db->listinfo("`typeid` = '$typeid' AND catid =
'$catid' ",'id
DESC',$page,20);//仅仅读取当前栏目下的同类别文章,如果要启用此模式,请去掉上一行代码并将本行开头的// 两斜杠去掉.

摘自:http://bbs.phpcms.cn/thread-243656-1-1.html

PHPCMS快速建站系列之类别调用及类别显示页面的更多相关文章

  1. PHPCMS快速建站系列之标签调用出错

    {pc:content action="position" posid="24" order="listorder ASC" thumb=& ...

  2. PHPCMS快速建站系列之常用标签

    <span class="Nmore"><a href="/index.php?m=content&c=index&a=lists&am ...

  3. PHPCMS快速建站系列之自定义分页函数

    内容分页的实现方法:{pc:content action="lists" catid="$catid" order="id DESC" nu ...

  4. PHPCMS快速建站系列之getcache()的用法

    /** * 读取缓存,默认为文件缓存,不加载缓存配置. * @param string $name 缓存名称 * @param $filepath 数据路径(模块名称) caches/cache_$f ...

  5. PHPCMS快速建站系列之标签循环嵌套

    标签循环嵌套方法,可以实现对PC标签循环调用,代码如下: 在此文件里/phpcms/lib/classes/template_cache.class.php 里的 template_parse 方法里 ...

  6. PHPCMS快速建站系列之phpcms v9 模板标签说明整理

    [摘要]本文介绍phpcms v9中模板标签使用说明. {template "content","header"} 调用根目录下phpcms\template\ ...

  7. PHPCMS快速建站系列之搜索功能

    默认模板的搜索功能代码 <div class="bd"> <form action="{APP_PATH}index.php" method= ...

  8. PHPCMS快速建站系列之邮箱验证

    1. 登录163邮箱,->设置,开启POP3服务->把SMTP服务器地址复制到PHPCMS后台. 2.开启客户端授权密码 3.填写相关信息,.可以在测试邮箱填入邮箱地址测试

  9. PHPCMS快速建站系列之后台内容自定义修改

    一.后台登录页面 背景图:\statics\images\admin_img 中的 login_bg.jpg 底部版权信息:\phpcms\languages\en 中的 system.lang.ph ...

随机推荐

  1. app-safeguard-record:record

    ylbtech-work-app-safeguard-record:record 1.返回顶部 1. 示数 示数一般是指机械.仪器.仪表.或者需要对数字进行公开的显示的对外数字的宣示.比如电度表(千瓦 ...

  2. Trie性能分析之敏感词过滤golang

    package util import ( "strings" ) type Node struct { //rune表示一个utf8字符 char rune Data inter ...

  3. xshell 连接 kali

    1   修改配置文件 vi /etc/ssh/sshd_config #PasswordAuthentication no 去掉#,并且将no修改为YES //kali中默认是yes PermitRo ...

  4. Http post请求案例

    public RmiRespBase sendHttpRes(String jsonParamStr, String url, String apiName,String systemId,Strin ...

  5. SpringBoot防XSS攻击

    1 . pom中增加依赖 <!-- xss过滤组件 --> <dependency> <groupId>org.jsoup</groupId> < ...

  6. 跟我一起做一个vue的小项目(十)

    接下来我们对城市列表页面进行优化,除了对数据优化,也会进行节流处理 //src\pages\city\components\Alphabet.vue <template> <ul c ...

  7. spring源码学习之容器的扩展(一)

    在前面的章节,我们一直以BeanFactory接口以及它的默认实现XmlBeanFactory为例进行解析,但是,spring还提供了另一个接口ApplicationContext,用于扩展BeanF ...

  8. css3正方体效果

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  9. bootstrap-datetimepicker下ie8对indexOf的支持问题

    问题: 由于ie8不支持indexOf这个方法,所以在引入bootstrap-datetimepicker.js的时候js会抛出错误. 解决: // 在bootstrap-datetimepicker ...

  10. poj 1679 The Unique MST 判断最小生成树是否唯一(图论)

    借用的是Kruskal的并查集,算法中的一点添加和改动. 通过判定其中有多少条可选的边,然后跟最小生成树所需边做比较,可选的边多于所选边,那么肯定方案不唯一. 如果不知道这个最小生成树的算法,还是先去 ...