PHPCMS快速建站系列之类别调用及类别显示页面
在需要调用类别的地方,比如列表页,首先写循环前面写上一句:
<?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快速建站系列之类别调用及类别显示页面的更多相关文章
- PHPCMS快速建站系列之标签调用出错
{pc:content action="position" posid="24" order="listorder ASC" thumb=& ...
- PHPCMS快速建站系列之常用标签
<span class="Nmore"><a href="/index.php?m=content&c=index&a=lists&am ...
- PHPCMS快速建站系列之自定义分页函数
内容分页的实现方法:{pc:content action="lists" catid="$catid" order="id DESC" nu ...
- PHPCMS快速建站系列之getcache()的用法
/** * 读取缓存,默认为文件缓存,不加载缓存配置. * @param string $name 缓存名称 * @param $filepath 数据路径(模块名称) caches/cache_$f ...
- PHPCMS快速建站系列之标签循环嵌套
标签循环嵌套方法,可以实现对PC标签循环调用,代码如下: 在此文件里/phpcms/lib/classes/template_cache.class.php 里的 template_parse 方法里 ...
- PHPCMS快速建站系列之phpcms v9 模板标签说明整理
[摘要]本文介绍phpcms v9中模板标签使用说明. {template "content","header"} 调用根目录下phpcms\template\ ...
- PHPCMS快速建站系列之搜索功能
默认模板的搜索功能代码 <div class="bd"> <form action="{APP_PATH}index.php" method= ...
- PHPCMS快速建站系列之邮箱验证
1. 登录163邮箱,->设置,开启POP3服务->把SMTP服务器地址复制到PHPCMS后台. 2.开启客户端授权密码 3.填写相关信息,.可以在测试邮箱填入邮箱地址测试
- PHPCMS快速建站系列之后台内容自定义修改
一.后台登录页面 背景图:\statics\images\admin_img 中的 login_bg.jpg 底部版权信息:\phpcms\languages\en 中的 system.lang.ph ...
随机推荐
- php函数基础(一)
一.函数结构 1.构成部分: 关键字 function
- linux命令行操作mysql数据库明细
连接数据库==> mysql -uroot -p 输入root密码 进入mysql操作后 下面的命令不要忘了最后结尾的; 1.选择数据库命令: use <数据库名> 2.查看表的引擎 ...
- Java虚拟机系列(三)---内存溢出情况及解决方法
因为Java虚拟机内存有堆内存.方法区.虚拟机栈.本地方法栈和程序计数器五部分组成,其中程序计数器是唯一一块不会发生内存溢出异常的内存区,所以只有四类内存区可能发生内存溢出异常,其中虚拟机栈和本地方法 ...
- hibernate4多对多Use of @OneToMany or @ManyToMany targeting an unmapped class:
出错之后先查了一下,大家有 @Entity 导错包的,不过我这里没错 import javax.persistence.Entity; 就是这个 还有的是没有注解@Table的,我这里也是没问题的 我 ...
- 通过java反射实现的excel数据导出
Excel.java @SuppressWarnings("deprecation") public static <T> void ExportExcel(Strin ...
- Tensorflow技巧
1.尽量控制图片大小在1024以内,不然显存会爆炸. 2.尽量使用多GPU并行工作,训练下降速度快. 3.当需要被检测的单张图片里物体太多时,记得修改Region_proposals的个数 4.测试的 ...
- Laravel Carbon获取 某个时间后N个月的时间
$time = "2020-11-20 00:00:00"; $res = (new Carbon)->setTimeFromTimeString($time)->ad ...
- MySQL系列(五)--二进制日志对主从复制的影响
MySQL复制是基于主库上的二进制日志来完成,复制是异步的,可能存在延迟 MySQL日志分为: 1.服务层日志:二进制日志.通用日志.慢查日志 2.存储引擎层日志:innodb中重做日志和回滚日志 二 ...
- [Array]122. Best Time to Buy and Sell Stock II(obscure)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- bzoj 1800 [Ahoi2009]fly 飞行棋——模拟
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1800 原来只想到一个弧是一条边. 然后发现不是.差点不会做.经Zinn提醒,不用枚举那条边由 ...