PHPCMS单页面新增缩略图、添加时间、发布的用户、浏览量
PHPCMS单页面新增缩略图、添加时间、发布的用户、浏览量
都知道,PHPCMS单页面,默认都是没有缩略图、添加司机、发布的用户和浏览量的;刚好在建一个站点的时候碰到了需要;下面是操作步骤:
一、新增 v9_page 表字段
ALTER TABLE v9_page ADD (`thumb` varchar(255) NOT NULL COMMENT '缩略图'), (`updatetime` int(10) unsigned NOT NULL DEFAULT '0'), (`username` varchar(20) NOT NULL COMMENT '发布用户'), (`inputtime` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间'), (`views` int(11) NOT NULL DEFAULT '0' COMMENT '点击数量');
二、模板文件新增缩略图选择框
1) 修改文件: phpcms/modules/content/templates/content_page.tpl.php
在
<tr> <th width="80"> <?php echo L('content');?></th> <td>
上方新增(在这里我就直接用中文了,没有添加语言包了,可以根据自己的需求来更改)
<!--添加缩略图--> <tr> <th>缩略图</th> <td><?php echo form::images('info[thumb]', 'thumb', $thumb, 'content');?></td> </tr>
2) 修改文件:/phpcms/modules/content/content.php
在
$_POST['info']['style'] = strip_tags($_POST['style_color']).';'.$style_font_weight;
下方新增
$_POST['info']['username'] = param::get_cookie('admin_username'); //这里是为单网页新增用户名
在
$this->page_db->update($_POST['info'],array('catid'=>$catid));
上方新增
$_POST['info']['updatetime'] = time(); //这里是为单页更新时间
在
$catid = $this->page_db->insert($_POST['info'],1);
上方新增
$_POST['info']['inputtime'] = time(); //这里是为单页新增添加时间
添加好上面的字段后,再新增单页面或修改单页面的时候这些字段都已经可以正常使用了;直接在前台模板中调用改字段即可,例: (缩略图:{$thumb}),(发布人:{$username})
三、新增单页面的点击次数
新增文件:/api/count_page.php
文件内容:
<?php defined('IN_PHPCMS') or exit('No permission resources.'); /** * 单网页添加点击统计 */ $db = ''; $db = pc_base::load_model('page_model'); if($_GET['id']) { $hitsid =intval($_GET['id']); $r = get_count($hitsid); if(!$r) exit; extract($r); hits($hitsid); }else{ exit('no data'); } /** * 获取点击数量 * @param $id */ function get_count($id) { global $db; $r = $db->get_one(array('catid'=>$id)); if(!$r) return false; return $r; } /** * 点击次数统计 * @param $contentid */ function hits($hitsid) { global $db; $r = $db->get_one(array('catid'=>$hitsid)); if(!$r) return false; $views = $r['views'] + 1; $sql = array('views'=>$views); return $db->update($sql, array('catid'=>$hitsid)); } ?> $('#hits').html('<?php echo $views?>');
新增好文件内容后,在单页面中,调用下面代码即可统计单页面的点击数量:
<span id="hits"></span> <script language="JavaScript" src="{APP_PATH}api.php?op=count_page&id={$catid}"></script>
以上就是PHPCMS单页面新增缩略图、添加时间、发布的用户、浏览量的操作步骤了。
Dcr163的博客
http://dcr163.cn/399.html(转载时请注明本文出处及文章链接)