您现在的位置是:首页 > cms教程 > phpcms教程phpcms教程
phpcms移植添加相关文章功能的方法
书瑶2025-05-26phpcms教程已有人查阅
导读添加相关文章功能相当有用,移植一个过来基本上可以实现比较复杂的页面内包含分类功能,做二次开发时可以省下不少力气。
添加相关文章功能相当有用,移植一个过来基本上可以实现比较复杂的页面内包含分类功能,做二次开发时可以省下不少力气。
用例:如果一个产品,属于一个厂家,而这个厂家是动态添加的,既不是一个分类,而是一个厂家的模型,这二者关联的时候使用这个添加相关的功能可以轻易实现。
学会使用phpcms中的类别管理和推荐位管理基本上可以满足文章管理的多数场景,如果能够理解mysql表的设计,可以使用模型管理这个大杀器,基本上能够想到的功能都能实现,之后再对【添加相关文章】功能进行设计和移植,模型功能能够再次爆发威力,进行各种关系映射。前台配合ajax和json,以及数据表的query函数可以整合实现相当复杂的功能和页面。
1,模型管理中添加一个万能字段。
然后在表单栏中填写:
2,在文章修改页面添加如下函数
用例:如果一个产品,属于一个厂家,而这个厂家是动态添加的,既不是一个分类,而是一个厂家的模型,这二者关联的时候使用这个添加相关的功能可以轻易实现。
学会使用phpcms中的类别管理和推荐位管理基本上可以满足文章管理的多数场景,如果能够理解mysql表的设计,可以使用模型管理这个大杀器,基本上能够想到的功能都能实现,之后再对【添加相关文章】功能进行设计和移植,模型功能能够再次爆发威力,进行各种关系映射。前台配合ajax和json,以及数据表的query函数可以整合实现相当复杂的功能和页面。
1,模型管理中添加一个万能字段。
然后在表单栏中填写:
<input type='hidden' name='info[rt]' id='rt' value='{FIELD_VALUE}' style='50' >
<ul class="list-dot" id="rt_text"></ul>
<div>
<input type='button' value="添加相关" onclick="omnipotent('selectid','?m=content&c=content&a=public_rtlist&modelid=29','添加相关文章',1)" class="button" style="width:66px;">
<span class="edit_content">
<input type='button' value="显示已有" onclick="show_rt({MODELID},{ID})" class="button" style="width:66px;">
</span>
</div>
注意上面的标红字体,需要和相关参数关联2,在文章修改页面添加如下函数
function show_rt(modelid,id) {
$.getJSON("?<?php echo "token=".$_SESSION['token'];?>&m=content&c=content&a=rt_getjson_ids&modelid="+modelid+"&id="+id, function(json){
var newrt_ids = '';
if(json==null) {
alert('没有添加相关文章');
return false;
}
$.each(json, function(i, n){
newrt_ids += "<li id='"+n.sid+"'>·<span>"+n.title+"</span><a href='javascript:;' class='close' onclick=\"remove_rt('"+n.sid+"',"+n.id+")\"></a></li>";
});
$('#rt_text').html(newrt_ids);
});
}
//移除相关文章
function remove_rt(sid,id) {
var rt_ids = $('#rt').val();
if(rt_ids !='' ) {
$('#'+sid).remove();
var r_arr = rt_ids.split('|');
var newrt_ids = '';
$.each(r_arr, function(i, n){
if(n!=id) {
if(i==0) {
newrt_ids = n;
} else {
newrt_ids = newrt_ids+'|'+n;
}
}
});
$('#rt').val(newrt_ids);
}
}
3,在content.php中填写如下函数
public function public_rtlist() {
ec_main::get_lib_c('format','',0);
$show_header = '';
$model_cache = getcache('model','commons');
if(!isset($_GET['modelid'])) {
showmessage(L('please_select_modelid'));
} else {
$page = intval($_GET['page']);
$modelid = intval($_GET['modelid']);
$this->db->set_model($modelid);
$where = '';
if($_GET['catid']) {
$catid = intval($_GET['catid']);
$where .= "catid='$catid'";
}
$where .= $where ? ' AND status=99' : 'status=99';
if(isset($_GET['keywords'])) {
$keywords = trim($_GET['keywords']);
$field = $_GET['field'];
if(in_array($field, array('id','title','keywords','description'))) {
if($field=='id') {
$where .= " AND `id` ='$keywords'";
} else {
$where .= " AND `$field` like '%$keywords%'";
}
}
}
$infos = $this->db->listinfo($where,'',$page,12);
$pages = $this->db->pages;
include $this->admin_tpl('rtlist');
}
}
public function rt_getjson_ids() {
$modelid = intval($_GET['modelid']);
$id = intval($_GET['id']);
$this->db->set_model($modelid);
$tablename = $this->db->table_name;
$this->db->table_name = $tablename.'_data';
$r = $this->db->get_one(array('id'=>$id),'rt');
if($r['rt']) {
$rt = str_replace('|', ',', $r['rt']);
$rt = trim($rt,',');
$where = "id IN($rt)";
$infos = array();
$this->db->table_name = 'ec_chang';
$datas = $this->db->select($where,'id,title');
foreach($datas as $_v) {
$_v['sid'] = 'v'.$_v['id'];
if(strtolower(CHARSET)=='gbk') $_v['title'] = iconv('gbk', 'utf-8', $_v['title']);
$infos[] = $_v;
}
echo json_encode($infos);
}
}
5增加模板rtlist.tpl.php[content/tpl]
<?php
defined('IN_ADMIN') or exit('No permission resources.');
include $this->admin_tpl('header','admin');
?>
<div class="pad-10">
<form name="searchform" action="" method="get" >
<input type="hidden" value="content" name="m">
<input type="hidden" value="content" name="c">
<input type="hidden" value="public_rtlist" name="a">
<input type="hidden" value="<?php echo $modelid;?>" name="modelid">
<table width="100%" cellspacing="0" class="search-form">
<tbody>
<tr>
<td align="center">
<div class="explain-col">
<select name="field">
<option value='title' <?php if($_GET['field']=='title') echo 'selected';?>><?php echo L('title');?></option>
<option value='keywords' <?php if($_GET['field']=='keywords') echo 'selected';?> ><?php echo L('keywords');?></option>
<option value='description' <?php if($_GET['field']=='description') echo 'selected';?>><?php echo L('description');?></option>
<option value='id' <?php if($_GET['field']=='id') echo 'selected';?>>ID</option>
</select>
<?php echo form::select_category('',$catid,'name="catid"',L('please_select_category'),$modelid,0,1);?>
<input name="keywords" type="text" value="<?php echo stripslashes($_GET['keywords'])?>" style="width:330px;" class="input-text" />
<input type="submit" name="dosubmit" class="button" value="<?php echo L('search');?>" />
</div>
</td>
</tr>
</tbody>
</table>
</form>
<div class="table-list">
<table width="100%" cellspacing="0" >
<thead>
<tr>
<th ><?php echo L('title');?></th>
<th width="100"><?php echo L('belong_category');?></th>
<th width="100"><?php echo L('addtime');?></th>
</tr>
</thead>
<tbody>
<?php foreach($infos as $r) { ?>
<tr onclick="select_list(this,'<?php echo safe_replace($r['title']);?>',<?php echo $r['id'];?>)" class="cu" title="<?php echo L('click_to_select');?>">
<td align='left' ><?php echo $r['title'];?></td>
<td align='center'><?php echo $this->categorys[$r['catid']]['catname'];?></td>
<td align='center'><?php echo format::date($r['inputtime']);?></td>
</tr>
<?php }?>
</tbody>
</table>
<div id="pages"><?php echo $pages;?></div>
</div>
</div>
<style type="text/css">
.line_ff9966,.line_ff9966:hover td{
background-color:#FF9966;
}
.line_fbffe4,.line_fbffe4:hover td {
background-color:#fbffe4;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function select_list(obj,title,id) {
var rt_ids = window.top.$('#rt').val();
var sid = 'v<?php echo $modelid;?>'+id;
if($(obj).attr('class')=='line_ff9966' || $(obj).attr('class')==null) {
$(obj).attr('class','line_fbffe4');
window.top.$('#'+sid).remove();
if(rt_ids !='' ) {
var r_arr = rt_ids.split('|');
var newrt_ids = '';
$.each(r_arr, function(i, n){
if(n!=id) {
if(i==0) {
newrt_ids = n;
} else {
newrt_ids = newrt_ids+'|'+n;
}
}
});
window.top.$('#rt').val(newrt_ids);
}
} else {
$(obj).attr('class','line_ff9966');
var str = "<li id='"+sid+"'>·<span>"+title+"</span><a href='javascript:;' class='close' onclick=\"remove_rt('"+sid+"',"+id+")\"></a></li>";
window.top.$('#rt_text').append(str);
if(rt_ids =='' ) {
window.top.$('#rt').val(id);
} else {
rt_ids = rt_ids+'|'+id;
window.top.$('#rt').val(rt_ids);
}
}
}
//-->
</SCRIPT>
</body>
</html>
本文标签:
很赞哦! ()
下一篇:phpcms的SEO标题设置方法
相关教程
图文教程
phpcms备份数据的方法
为什么要记录phpcms的版本呢?为了防止因版本升级后数据库无法恢复,管理员应该养成在备份数据时记录相应平台版本的习惯。同时还要提醒大家记录这时的管理员账号密码
phpcms服务器正常换到本地更新缓存页面空白读不到缓存
网站在服务器上运行正常,弄到我电脑上进入网站后台,更新缓存页面空白,访问首页还是空白。调试发现是在include/common.inc.php中执行到下面不执行了
PHPcms系统简单使用教程
1.站点/发布点的新建1.1 发布点的新建:发布点是设置站点与服务器之间的链接配置。设置 - 发布点管理 - 添加发布点发布点名:可以与接下来的站点名称相同
phpcmsV9网站域名变更后刷新所有缓存栏目链接总是不变怎么办
网站在发展的过程中,很可能多次的修改域名。那么在PHPCMS V9中我们要怎么进行设置呢?请进行以下步骤的修改:修改/caches/configs/system.php里面所有和域名有关的,把以前的老域名修改为新域名就可以了。
相关源码
-
(自适应)帝国cms7.5文章新闻博客整站源码( 带会员中心)本模板基于帝国CMS内核开发,为新闻资讯、个人博客及作品展示类网站设计。采用响应式布局技术,确保在手机、平板和电脑等不同设备上都能获得良好的浏览体验。查看源码 -
响应式粉色美容整形化妆品pbootcms网站模板开源源码该网站模板为美容整形、化妆品企业设计,采用响应式布局确保在手机、平板及PC端自动适配显示效果。基于PbootCMS内核开发,支持一键替换图文内容快速转换至其他行业应用。查看源码 -
(自适应)挖掘机大型采矿设备pbootcms网站源码下载本模板基于PbootCMS系统开发,专为重型机械设备行业设计,特别适合挖掘机、采矿设备、工程机械等工业设备展示。采用响应式布局技术,确保各类设备参数和图片在不同终端上都能清晰展示。查看源码 -
(自适应html5)重工业钢铁机械设备网站pbootcms响应式模板下载为重工业领域打造的响应式网站模板,助力企业高效展示产品与服务,基于PbootCMS开发的工业级网站模板,特别适合钢铁制造、机械设备生产等重工业企业使用。查看源码 -
帝国CMS7.5H5小游戏模板游戏攻略下载网整站源码本模板基于帝国CMS系统开发,为H5小游戏和APP应用资讯类网站设计。模板架构针对小游戏行业特点优化,支持游戏发布、资讯分享、应用推荐等功能,满足各类小游戏门户网站的建设需求。查看源码 -
(自适应)简繁双语响应式服装服饰西装工装校服定制pbootcms模板本模板基于PbootCMS内核开发,为服装服饰行业量身打造,尤其适合西装定制、工装生产、校服订制等服装类企业使用。模板采用响应式布局设计,确保在手机、平板、电脑查看源码
| 分享笔记 (共有 篇笔记) |
