转载]PhpCms V9调用指定栏目子栏目文章的两种方法

时间:2022-10-25 21:40:55
PhpCms V9调用指定栏目子栏目文章的两种方法 第一种、直接写子栏目id ,用cat in {pc:get sql="SELECT * from v9_news where status=99 and catid in(21,22,23,24,25) order by id DESC" num="7" return="data"} {loop $data $r} {str_cut($r['title'],40)}({date('m-d',$r[inputtime])}) {/loop} {/pc} 这种方法的好处:可以想取那个栏目可以自定义 缺点:要写多个id,后台增加了栏目的话得再把id写进去 第二种,根据父栏目id,如上面的21,22,23,24,25都是 15下面的子栏目,可以这样写: {loop subcat(15)  $k $v} {php $subcatid[] = $k;} {/loop} {php $subcatid  = implode(',', $subcatid);} {pc:get sql="SELECT * from v9_news where status=99 and catid in ($subcatid) order by id DESC" num="7" return="data" } {loop $data $r} [{$CATEGORYS[$r[catid]][catname]}]{str_cut($r['title'],40)}[{date('Y-m-d',$r[inputtime])}] {/loop} {/pc} 好处:只要写一个父栏目id,自动取下级子栏目id 缺点:循环父栏目下所有的子栏目id,如果某个子栏目的内容不想显示的话,不好实现 两种方法各有利弊,视情况选之 ************************************调用一个栏目下的最新,带缩略图的文章***************************************** phpcms v9 调用一个栏目下的最新,带缩略图的文章,同时调用出起内容简介(多个栏目ID调用) 以下为模板中的标签 {get sql="select*from phpcms_content where catid>=79 and catid<=85 and status=99 and posids=1 and `thumb`!='' order by updatetime desc" rows="1"} {str_cut($r[title], 40)} phpcms <wbr><wbr>v9网站开发常用代码 {str_cut($r[description],100)} {/get} 在使用get的时候注意一点就是{/get} get的结束标签。 说明: phpcms_content 这是数据库里边数据表的名称,如果你的数据表前缀进行了修改,这里也必须进行修改。如果你在安装phpcms的时候设置的为woshi_. 那么这里就应该是woshi_content catid>=79 and catid<=85    栏目ID大于等于75并且栏目id小于等于85.   也就是调用栏目ID75 76 77 78 79 80 81 82 83 84 85的文章。 posids=1 文章类型为首页推荐 status=99 文章已经通过审核 `thumb`!='' 缩略图不为空,也就是必须要有缩略图 {$r[url]} 内容页的地址 {str_cut($r[title], 40)} 文章标题,长度限制为40 {thumb($r[thumb], 110, 75)} 缩略图地址   缩略图大小限制为width=110px height=75px {str_cut($r[description],100) 文章简介调用 简介长度为100 通过上面的调用及模板语句(div li ),我通过css的控制可得出如下test.gif。 具体的css部分,我们后面在讲。 *******************************************************************************
1.去掉标题限制后出现的省略号 {str_cut($r[title],36,”)} 2.格式化时间 格式化时间 2011-05-06 11:22:33 {date(‘Y-m-d H:i:s’,$r[inputtime])} 格式化时间 2011年05月06日 {date(‘Y年m月d日’,$r[inputtime])} 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} ·{str_cut($r[title],22,”)} {/loop} {/pc} 4.显示栏目名称(只是名称,不带链接) {$catname} 显示栏目名称和链接(可以点击) {$CATEGORYS[$r['catid']]['catname']} 5.获取父栏目id/获取父栏目名称 {$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} {str_cut($r[uname],28,”)} {/loop} {/pc} 7.调用子栏目(在栏目首页模板需要用到) {pc:content action=”category” catid=”$catid” num=”25″ siteid=”$siteid” order=”listorder ASC”} {loop $data $r} {$r[catname]} | {/loop} {/pc} 8.显示指定id的栏目名称 (例子这里catid=22) {$CATEGORYS[22]['catname']} 9.在文章面前显示文章类别 {pc:content action=”lists” catid=”79″ order=”listorder DESC” num=”14″ } {loop $data $n $r} {if $TYPE[$r[typeid]][name]}[ {$TYPE[$r[typeid]][name]}] {/if}{str_cut($r[title],33,”)} {/loop} {/pc} 10.指定变量循环增长(幻灯片经常用到) {pc:content action=”lists” catid=”66″ order=”listorder DESC” thumb=”1″ num=”5″ } {php $num = 0} {loop $data $r} linkarr[{$num}] = “{$r[url]}”; picarr[{$num}] = “{$r[thumb]}”; textarr[{$num}] = “{str_cut($r[title],36,”)}”; {php $num++} {/loop} {/pc} 11.文章调用使用limit {pc:content action=”position” posid=”36″ num=”1″ order=”listorder DESC limit 1,1–” } 其他都是跟以前一样使用 {pc:content action=”position” posid=”31″ order=”listorder DESC” limit=’1,8–’} {loop $data $r} {str_cut($r[title],36,”)} {/loop} {/pc} 12.文章从指定位置开始调用 起始位置为5,调用3条。相当于limit功能。 {pc:content action=”position” posid=”27″ order=”listorder DESC” num=”3″ start=”5″} {loop $data $r} {str_cut($r[description],115)}… {/loop} {/pc} 13.文章列表页调用关键字,或者首页调用关键字 注意: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} {$r[title]} {php $keywords = explode(‘,’,$r[keywords]);} 文章标签: {loop $keywords $keyword} {$keyword} {/loop} {/loop} {/pc} 14.每当列表几行的时候出现一次某些符号(比如首页里面的文章推荐,一行显示两条,在这两条中间想加一条竖线 | 就用到这个代码了) 数量大的话就容易出错,因为模运算嘛~~呵呵 不过一般也就4个标题以下 {pc:content action=”position” posid=”8″ order=”listorder DESC” num=”2″} {loop $data $r} {str_cut($r[title],26,”)}{if $n%2==1} |{/if} {/loop} {/pc} 15.v9 列表页完美支持自定义段调用 {pc:content action=”lists” catid=”$catid” num=”25″ order=”id DESC” page=”$page” moreinfo=”1″} {loop $data $r} [{$r['字段名']}]> {$r[title]} {/loop} {$pages} {/pc} 16.当前栏目调用父级及以下栏目信息方法 其他代码 该咋地还是要咋地 。这是要素 {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”} 17.V9表单功能 提交之后如何返回当前页面,而不是默认的首页文件地址 找到 phpcmsmodulesformguideindex.php文件第73行 showmessage(L(‘thanks’), APP_PATH); 修改成 如下代码即可实现自动返回前一页 showmessage(L(‘thanks’), HTTP_REFERER); 18.v9 首页或分页自定义字段调用 和15差不多 第一普通列表或栏目调用自定义字段 在{pc:content action=”lists” 后加上副表moreinfo=1 (等于1时显示,0时不显示) 例子: {pc:content action=”lists” moreinfo=1 catid=”2″ order=”id DESC” num=”4″} {loop $data $key $val} {$val['title']} 价格:{str_cut($v['自定义段'],100)} //100 是字数
 {/loop} {/pc} 第二种推荐位调用自定义字段 在模型里加好自定义字段后,必须把“在推荐位标签中调用”点击“是“ 然后用同一样的方法去调节数据就OK了,记住,如果你加了文章,必须去更新文章才会显示,自定义段在推荐中只显示你选择后,选择前加的加文章不显示,更新一下文章就显示了 例子: {pc:content action=”position” posid=”推荐位id” num=”30″ thumb=”1″ moreinfo=”1″ order=”listorder DESC”} {loop $data $key $val} ”{$val['title']}” {str_cut($val['title'],20)} {/loop} {/pc} 20.编辑器上传图片自动使用标题作为alt参数 一: 修改 statics/js/ckeditor/plugins/image/dialogs/image.js 找到 accessKey:’T',’default’:” 替换成 accessKey:’T',’default’:$(‘#title’).val()
二: 清除浏览器缓存 21.增加文章的随机点击数 找到100行的$views = $r['views'] +1 修改为:
$rand_nums=rand(79,186); $views = $r['views'] + $rand_nums; 表示点击一次,增加79到186次不等 ————————————————————- tips:某些版本出错民间解决方法 1.缩略图以及图集无法上传 phpcmslibsclassesattachment.class.php 请把24行的(也有可能是23行) $this->upload_func = ‘copy’; 改成 $this->upload_func = ‘move_uploaded_file’; 2.碎片模块搜索文章看不到栏目 phpcmsmodulesblocktemplatessearch_content.tpl.php 13行改成