PHPCMS V9 二次开发常用代码集

it2022-06-30  79

0:调用最新文章,带所在版块

{pc:get sql="SELECT a.title, a.catid, b.catid, b.catname, a.url as turl ,b.url as curl, a.id FROM `v9_news` a, `v9_category` b WHERE a.catid = b.catid ORDER BY `a`.`id` DESC " num="15" cache="300"} {loop $data $r} <h6><font class="cate"><a href="http://archive.cnblogs.com/a/2482088/{$r[curl]}" target="_blank" rel="nofollow"> class="gray" href="http://archive.cnblogs.com/a/2482088/{$r[turl]}" target="_blank" rel="nofollow"> {/loop} {/pc}

1.截取调用标题长度

{str_cut($v[title],36,'')} {str_cut($v['title'],34)} 超出用 ... 代替 {str_cut($v['title'],34, '???')}超出用 ???代替 {str_cut($v['title'],34,'')}超出不用任何字符代替

2.格式化时间

调用格式化时间 2011-05-06 11:22:33 {date('Y-m-d H:i:s',$r[inputtime])} <span class="rt">{date('m-d',$v['inputtime'])}</span>

3.多栏目调用&多推荐位调用

调用需求:文章范围为59 60 61三个栏目,并且推送到了27 和28两个推荐位;从第三条开始,连续调用7篇文章。

{pc:get sql="SELECT * FROM v9_news WHERE id IN (SELECT id FROM v9_position_data WHERE posid in(27,28) and catid in(59,60,61)) order by listorder DESC" cache="3600" start="3" num="7" return="data" } {loop $data $n $r} <li>·<a target="_blank" href="http://archive.cnblogs.com/a/2482088/{$r[url]}" target="_blank" rel="nofollow"> ($r[title],22,'')}</a></li> {/loop} {/pc}

4.显示栏目名称、链接

{$CATEGORYS[$r[catid]][url]}

{$CATEGORYS[$r[catid]][catname]}

{$CATEGORY[$catid][parentid]}

父栏目名称:{$CATEGORYS[$CAT[parentid]][catname]}

6.外部数据源调用

 

dedecmsdb 在后台数据源处添加 {pc:get sql="SELECT * FROM cq_member where mtype='企业' " cache="3600" dbsource="dedecmsdb" num="7" return="data"} {loop $data $r} <a href="http://archive.cnblogs.com/member/index.php?uid={$r[userid]}" target="_blank" rel="nofollow"> ($r[uname],28,'')}</a> {/loop} {/pc}

 

7.调用子栏目(在栏目首页模板需要用到)

{pc:content action="category" catid="$catid" num="25" siteid="$siteid" order="listorder ASC"} {loop $data $r} <a href="http://archive.cnblogs.com/a/2482088/{$r[url]}" target="_blank" rel="nofollow"> {/loop} {/pc}

8.在文章面前显示文章类别

{pc:content action="lists" catid="79" order="listorder DESC" num="14" } <?php $TYPE = getcache('type_content','commons');?> {loop $data $n $r} <li>{if $TYPE[$r[typeid]][name]}<span style="color:#CC6600">[ {$TYPE[$r[typeid]][name]}] </span>{/if}<a href="http://archive.cnblogs.com/a/2482088/{$r[" target="_blank" rel="nofollow"> target="_blank">{str_cut($r[title],33,'')}</a></li> {/loop} {/pc}

9.文章从指定位置开始调用

起始位置为5,调用3条。相当于limit功能。 {pc:content action="position" posid="27" order="listorder DESC" num="3" start="5"} {loop $data $r} <a href="http://archive.cnblogs.com/a/2482088/{$r[url]}" target="_blank" rel="nofollow"> {/loop} {/pc}

10.文章列表页调用关键字,或者首页调用关键字

注意:explode(',',$r[keywords]);是将文章关键词通过英文逗号分离,也就是说每一篇文章都要以逗号 间隔关键字,否则调用出来会 是全部作为一个关键字。如果是空格间隔关键字,将explode(',',$r [keywords]);改成explode(' ',$r[keywords]); {pc:content action="lists" catid="$catid" num="10" order="id DESC" page="$page"} {loop $data $r} <a href="http://archive.cnblogs.com/a/2482088/{$r[url]}" target="_blank" rel="nofollow"> {php $keywords = explode(',',$r[keywords]);} <b>文章标签:</b> {loop $keywords $keyword} <a href="http://archive.cnblogs.com/a/2482088/{APP_PATH}index.php?m=content&c=tag&catid={$catid}&tag={urlencode($keyword)}" target="_blank" rel="nofollow"> class="blue"> {$keyword}</a> {/loop} {/loop} {/pc}

11.每当列表几行的时候出现一次某些符号(比如首页里面的文章推荐,一行显示两条,在这两条中间想加一条竖线 | 就用到这个代码了)

数量大的话就容易出错,因为模运算嘛~~呵呵 不过一般也就4个标题以下 {pc:content action="position" posid="8" order="listorder DESC" num="2"} {loop $data $r} <a style="color:#040605" title="{$r[title]}" href="http://archive.cnblogs.com/a/2482088/{$r[url]}" target="_blank" rel="nofollow"> [title],26,'')}</a>{if $n%2==1} |{/if} {/loop} {/pc}

 

12.V9 列表页完美支持自定义段调用

{pc:content action="lists" catid="$catid" num="25" order="id DESC" page="$page" moreinfo="1"} {loop $data $r} <a href="http://archive.cnblogs.com/a/2482088/{$r[url]}" target="_blank" rel="nofollow"> {/loop} <div class="pagebar">{$pages}</div> {/pc}

13.当前栏目调用父级及以下栏目信息方法

其他代码 该咋地还是要咋地 。这是要素 {php $arrchildid = $CATEGORYS[$CAT[parentid]][arrchildid]} {pc:get sql="SELECT * FROM v9_news where catid in($arrchildid) cache="3600" page="$page" num="12" return="data"}

14.V9表单功能 提交之后如何返回当前页面,而不是默认的首页文件地址

找到 phpcms\modules\formguide\index.php文件第73行 showmessage(L('thanks'), APP_PATH); 修改成 如下代码即可实现自动返回前一页 showmessage(L('thanks'), HTTP_REFERER);

15.V9 首页或分页自定义字段调用

第一普通列表或栏目调用自定义字段 在{pc:content action="lists" 后加上副表moreinfo=1 (等于1时显示,0时不显示) 例子: {pc:content action="lists" moreinfo=1 catid="2" order="id DESC" num="4"} <ul> {loop $data $key $val} <li><a href="http://archive.cnblogs.com/a/2482088/{$val[" target="_blank" rel="nofollow"> <br>价格:{str_cut($v['自定义段'],100)} //100 是字数 </li> {/loop} </ul> {/pc}第二种推荐位调用自定义字段在模型里加好自定义字段后,必须把“在推荐位标签中调用”点击“是“然后用同一样的方法去调节数据就OK了,记住,如果你加了文章,必须去更新文章才会显示,自定义段在推荐中只显示你选择后,选择前加的加文章不显示,更新一下文章就显示了例子:{pc:content action="position" posid="推荐位id" num="30" thumb="1" moreinfo="1"order="listorder DESC"}{loop $data $key $val}<LI><a href="http://archive.cnblogs.com/a/2482088/{$val[" target="_blank" rel="nofollow"> ['title']}" height=36 width=98 /></a><a href="http://archive.cnblogs.com/a/2482088/{$val[" target="_blank" rel="nofollow"> {/loop}{/pc}

16.编辑器上传图片自动使用标题作为ALT参数

一: 修改 statics/js/ckeditor/plugins/image/dialogs/image.js 找到 accessKey:'T','default':'' 替换成 accessKey:'T','default':$('#title').val()二: 清除浏览器缓存

 

 

16.调用手机端站点名称

$WAP['sitename']}

 

 

 

 

 

 

 

17.增加文章的随机点击数

找到100行的$views = $r['views'] +1 修改为: $rand_nums=rand(79,186); $views = $r['views'] + $rand_nums; 表示点击一次,增加79到186次不等 ------------------------------------------------------------- tips:某些版本出错民间解决方法 1.缩略图以及图集无法上传 \phpcms\libs\classes\attachment.class.php 请把24行的(也有可能是23行) $this->upload_func = 'copy'; 改成 $this->upload_func = 'move_uploaded_file'; 2.碎片模块搜索文章看不到栏目 phpcms\modules\block\templates\search_content.tpl.php 13行改成 <td><?php if(isset($_GET['dosubmit'])){?><div class="rt"><a href="javascript:void(0)" target="_blank" rel="nofollow"> echo L('folded_up_in_search_of')?></a></div><?php } echo form::select_category('', $catid, 'name="catid" id="catid"', '', '', '0', 1)?> </td>

转载于:https://www.cnblogs.com/yuan9580/p/10675057.html


最新回复(0)