侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

dedecms v5.7与v5.6栏目增加缩略图的方法

框架(架构)  /  管理员 发布于 7年前   182

本文实例讲述了dedecms v5.7与v5.6栏目增加缩略图的方法。

分享给大家供大家参考。具体分析如下:

栏目缩略图功能是dedecms系统不具备的一个功能了,如果你想给你的栏目增加一个缩略图上传功能我们需要来进行自定义二次开发了,下面我把一个朋友写的过程分享给大家,这里我也自己经过dedecmsv5.7测试过,没有任何问题.

此功能添加涉及到以下文件:

dede/catalog_add.php  
dede/catalog_edit.php  
dede/templets/catalog_add.htm  
dede/templets/catalog_edit.htm  
include/taglib/channel.lib.php

此升级修改方法,在V5.7,V5.7sp1 测试通过,其他版本未测试,原理基本相同,请大家自行测试是否可行.

首先给 栏目表(`dede_arctype`)增加一个字段typeimg,代码如下:
代码如下:

alter table `dede_arctype` add `typeimg` varchar(200) NOT NULL default ;

修改catalog_add.php文件,打开dede/catalog_add.php,查找:
代码如下:

$queryTemplate = "insert into `dede_arctype`  
//将  
(reid,topid,sortrank,typename,typedir,  
//替换为:(reid,topid,sortrank,typename,typedir,typeimg,   
//将  
('~reid~','~topid~','~rank~','~typename~','~typedir~',   
//替换为:  
('~reid~','~topid~','~rank~','~typename~','~typedir~','~typeimg~',   
//查找  
$in_query = "INSERT INTO `dede_arctype`  
//将  
(reid,topid,sortrank,typename,typedir,   
//替换为:  
(reid,topid,sortrank,typename,typedir,typeimg,   
//将  
('$reid','$topid','$sortrank','$typename','$typedir',   
//替换为:  
('$reid','$topid','$sortrank','$typename','$typedir','$typeimg',

保存catalog_add.php

下面修改catalog_edit.php文件,打开dede/catalog_edit.php,查找
代码如下:

$upquery = "Update `dede_arctype` set在 typedir='$typedir',

其下面增加一行:
代码如下:

`typeimg`='$typeimg'

保存catalog_edit.php

开始修改栏目添加模板文件,打开dede/templets/catalog_add.htm,在最上面找到这个段,

代码如下:

<title>栏目管理</title> <link href="https:/cms/css/base.css" rel="stylesheet" type="text/css">

替换为: 

代码如下:

<title>栏目管理</title> <link href="https:/cms/css/base.css" rel="stylesheet" type="text/css"> <script language="javascript" src="https:/cms/../include/js/dedeajax2.js"></script> <script language='javascript' src="https:/cms/js/main.js"></script> <script type="text/javascript" src="https:/cms/js/calendar/calendar.js"></script>

列表命名规则,代码如下:

<tr> <td height="26" style="padding-left:10px;">列表命名规则:</td> <td> <input name="namerule2" type="text" id="namerule2" value="{typedir}/list_{tid}_{page}.html" class="pubinputs" style="width:250px" /> <img src="https:/cms/images/help.gif" alt="帮助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvar3')"/></td> </tr>

在标签下面增加一行:
代码如下:

<!--增加栏目缩略图--> <tr> <td width="90" style="padding-left:10px;">栏目图片:</td> <td width="560"> <table width="100%" border="0" cellspacing="1" cellpadding="1"> <tr> <td height="30"> <input name="typeimg" type="text" id="typeimg" style="width:240px" /> <input type="button" value="本地上传" style="width:70px;cursor:pointer;display:none" /> <iframe name='uplitpicfra' id='uplitpicfra' src='https:/cms/' style='display:none'></iframe> <span class="litpic_span"><input name="litpic" type="file" id="litpic" onChange="SeePicNew(this, 'divpicview', 'uplitpicfra', 165, 'archives_add.php');" size="1" class='np coolbg'/></span> <input type="button" name="Submit2" value="选择图片" style="margin-left:8px;" onClick="SelectImage('form1.typeimg','small');" class='np coolbg'/> <input type="button" name="Submit2" value="裁剪" style="margin-left:8px;" onClick="imageCut('typeimg');" class='np coolbg'/> <input type='checkbox' class='np' name='ddisremote' value='1' id='ddisremote'/>远程
(栏目模板里用{dede:field.typeimg /}调用 </td> </tr> </table> </td> <td width="150" align="center"> <div id='divpicview' class='divpre'></div> </td> </tr> <!--增加栏目缩略图-->

保存catalog_add.htm,开始修改栏目编辑模板文件,

打开dede/templets/catalog_edit.htm,在最上面找到这个段,代码如下:

代码如下:

<title>栏目管理</title> <link href="https:/cms/css/base.css" rel="stylesheet" type="text/css">

替换为: 

代码如下:

<title>栏目管理</title> <link href="https:/cms/css/base.css" rel="stylesheet" type="text/css"> <script language="javascript" src="https:/cms/../include/js/dedeajax2.js"></script> <script language="javascript" src="https:/cms/js/main.js"></script> <script type="text/javascript" src="https:/cms/js/calendar/calendar.js"></script>

查找 

代码如下:

<tr><td height="26" style="padding-left:10px;">列表命名规则:</td> <td> <input name="namerule2" type="text" id="namerule2" value="<?php echo $myrow['namerule2']?>" size="40" class="iptxt" /> <img src="https:/cms/images/help.gif" alt="帮助" width="16" height="16" border="0" style="cursor:pointer" onClick="ShowHide('helpvar3')"/></td> </tr>

在其下面增加一行: 

代码如下:

<!--增加栏目缩略图--> <tr> <td width="90" height="81" style="padding-left:10px;">栏目图片:</td></td> <td width="500"> <input name="typeimg" type="text" id="typeimg" style="width:300px" value="<?php echo $myrow['typeimg']?>"><input type="button" name="Submit" value="浏览..." style="width:70px" onClick="SelectImage('form1.typeimg','');"> <input type="button" name="Submit2" value="裁剪" style="margin-left:8px;" onClick="imageCut('typeimg');" class='np coolbg'/> <input type='checkbox' class='np' name='ddisremote' value='1'> 远程
(栏目模板里用{dede:field.typeimg /}调用) </td> <td align="center"> <img src="https:/cms/<?php if($myrow['typeimg']!="") echo $myrow['typeimg']; else echo "images/pview.gif";?>" width="150" height="100" id="picview" name="picview"> </td> </tr> <!--增加栏目缩略图-->

保存catalog_edit.htm 

至此已经修改完成!


栏目图片的添加或修改图片时在(栏目管理>高级选项)里面就会自动出现栏目图片添加的选择.

点击选择图片.弹出窗口内选择浏览上传就OK.

注意:前台栏目标签调用的时候,还需要改一个文件,才能实现栏目图片显示,否则只能通过sql语句才能显示图片。

打开:include/taglib/channel.lib.php,找到如下代码:

代码如下:

if($type=='top') { $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description From `dede_arctype` where reid=0 And ishidden<>1 order by sortrank asc limit 0,$row"; } else if($type=="son") { //if($_sys_globals['typeid']>0) $typeid = $_sys_globals['typeid']; if($typeid==0) { return ''; } $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description From `dede_arctype` where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row"; } else if($type=="self") { if($reid==0) { return ''; } $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description From `dede_arctype` where reid='$reid' And ishidden<>1 order by sortrank asc limit 0,$row"; }

替换成下面的代码:

if($type=='top') { $sql = "Select id,typename,typeimg,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description From `dede_arctype` where reid=0 And ishidden<>1 order by sortrank asc limit 0,$row"; } else if($type=="son") { //if($_sys_globals['typeid']>0) $typeid = $_sys_globals['typeid']; if($typeid==0) { return ''; } $sql = "Select id,typename,typeimg,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description From `dede_arctype` where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row"; } else if($type=="self") { if($reid==0) { return ''; } $sql = "Select id,typename,typeimg,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description From `dede_arctype` where reid='$reid' And ishidden<>1 order by sortrank asc limit 0,$row"; }

调用方法:

<img src="https:/cms/[field:typeimg /]" />

希望本文所述对大家的dedecms建站有所帮助。


  • 上一条:
    DEDECMS显示英文日期时间的方法
    下一条:
    dedecms中sql标签调用数据实例分析
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Filament v3.1版本发布(0个评论)
    • docker + gitea搭建一个git服务器流程步骤(0个评论)
    • websocket的三种架构方式使用优缺点浅析(0个评论)
    • ubuntu20.4系统中宿主机安装nginx服务,docker容器中安装php8.2实现运行laravel10框架网站(0个评论)
    • phpstudy_pro(小皮面板)中安装最新php8.2.9版本流程步骤(0个评论)
    • 近期文章
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2018-05
    • 2020-02
    • 2020-03
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-11
    • 2021-03
    • 2021-09
    • 2021-10
    • 2021-11
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-08
    • 2023-08
    • 2023-10
    • 2023-12
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客