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

<?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. windows下docker 启动jenkins成功,浏览器无法访问,拒绝了我们的连接

    [问题现象] 在Windows下使用docker启动了一个jenkins,翻越了无数的坑,最后的启动命令为 docker run --name jenkins -u root -p 8000:8000 ...

  2. c++容器中map的应用

    原文链接:https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关 ...

  3. SQLSTATE[HY000] [2002] 乱码

    string(59) "SQLSTATE[HY000] [2002] ����Ŀ����������ܾ����޷����ӡ� " 实际意思是:SQLSTATE[HY000] [20 ...

  4. 用惯了jquery, 想用angularjs 还真不好理解

    jquery 比较直白,什么都是操作dom 节点. angularjs 就好比 thinkphp, ci 等框架,有自己约定的格式和方式.需要遵循它的规则,研究中... 比如说我,用了很长事件的jqu ...

  5. nginx 下开启pathinfo模式

    前几天自己新弄了个服务器,nginx的环境, 看到thinkcmf的框架,下载下来准备研究下,安装完成后,发现 url 是 普通模式,然后我就按照那个手册去后台开启了pathinfo模式,这一改完蛋了 ...

  6. for循环遍历json(附习题及答案)

    三种方法 var mapColumn = { "vdoing" : "访问深度", "_visitorNumber": "访问量& ...

  7. Firefox Developer Edition - Mozilla

    冰狐浏览器开发者工具:https://www.mozilla.org/en-US/firefox/developer/ 冰狐浏览器开发者工具:https://www.mozilla.org/en-US ...

  8. 在C#应用中使用Common Logging日志接口

    我在C#应用中一般使用log4net来记录日志,但如果项目中有个多个工程,那么没有工程都需要引用log4neg,感觉很不爽.不过今日在开spring.net的时候,看到了有个通用日志接口Common ...

  9. Web三大组件之控制器组件Servlet(转载)

    Servlet:主要用于处理客户端传来的请求,并返回响应.获取请求数据>处理请求>完成响应 过程:客户端发送请求----HTTP服务器接收请求,HTTP服务器只负责解析静态HTML界面,其 ...

  10. 关于neo4j的嵌入式和驱动包模式该如何选择,还请解惑

    看了网上的一些资料和Neo4j权威指南这本书.与图遍历相关的介绍都是基于嵌入式模式下的java Api.但是个人觉得在实际的项目中,嵌入式的模式,代码必须放在数据库所在服务器上,且服务器的启停操作都在 ...