phpcms v9笔记之模板制作案例

来源:互联网 发布:linux计数统计文件命令 编辑:程序博客网 时间:2024/05/22 08:24

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

[html] view plaincopyprint?
  1. {pc:get sql="SELECT a.title, a.catid, b.catid, b.catname, a.url as turl ,b.url as curl,  
  2.   
  3. a.id FROM `v9_news` a, `v9_category` b WHERE a.catid = b.catid ORDER BY `a`.`id` DESC "  
  4.   
  5. num="15" cache="300"}  
  6. {loop $data $r}  
  7. <h6>  
  8.     <font class="cate">  
  9.         <a href="http://xzl52199.blog.163.com/blog/{$r[curl]}">[{$r[catname]}]</a>  
  10.     </font>  
  11.     <a href="http://xzl52199.blog.163.com/blog/{$r[turl]}" title="{$r[title]}">{str_cut($r['title'],26)}</a>  
  12. </h6>  
  13. {/loop}  
  14. {/pc}  
  15.   
  16. ====<font class="cate"><a href="http://xzl52199.blog.163.com/blog/{$r[curl]}">[{$r[catname]}]</a></font>所在版块的调用  

  截取调用标题长度

[html] view plaincopyprint?
  1. {str_cut($v[title],36,'')}  
  2.   
  3. {str_cut($v['title'],34)} 超出用 ... 代替  
  4.   
  5. {str_cut($v['title'],34, '???')}超出用 ???代替  
  6.   
  7. {str_cut($v['title'],34,'')}超出不用任何字符代替  

  格式化时间

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

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

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

[html] view plaincopyprint?
  1. {pc:get sql="SELECT * FROM v9_news WHERE id IN (SELECT id FROM v9_position_data WHERE posid  
  2.   
  3. in(27,28) and catid in(59,60,61)) order by listorder DESC" cache="3600" start="3" num="7"  
  4.   
  5. return="data" }  
  6. {loop $data $n $r}  
  7. <li>·<a target="_blank" href='http://xzl52199.blog.163.com/blog/{$r[url]}' title="{$r[title]}" style="color:Black;">{str_cut  
  8.   
  9. ($r[title],22,'')}</a></li>  
  10. {/loop}  
  11. {/pc}  

  显示栏目名称(只是名称,不带链接)

[html] view plaincopyprint?
  1. {$catname}  
  2.   
  3. 显示栏目名称和链接(可以点击)  
  4.   
  5. <a href="http://xzl52199.blog.163.com/blog/{$CATEGORYS[$r[catid]][url]}">{$CATEGORYS[$r['catid']]['catname']}</A>  

  获取父栏目id/获取父栏目名称

[php] view plaincopyprint?
  1. {$CATEGORY[$catid][parentid]}  
  2. 父栏目名称:{$CATEGORYS[$CAT[parentid]][catname]}  

  外部数据源调用

[php] view plaincopyprint?
  1. dedecmsdb 在后台数据源处添加  
  2. {pc:get sql="SELECT * FROM cq_member where mtype='企业' " cache="3600" dbsource="dedecmsdb"  
  3.   
  4. num="7" return="data"}  
  5.   
  6. {loop $data $r}  
  7.   
  8. <a href="/member/index.php?uid={$r[userid]}" title="{$r[uname]}" target="_blank">  
  9. {str_cut($r[uname],28,'')}</a>  
  10.   
  11. {/loop}  
  12.   
  13. {/pc}  

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

[php] view plaincopyprint?
  1. {pc:content action="category" catid="$catid" num="25" siteid="$siteid" order="listorderASC"}  
  2. {loop $data $r}  
  3. <a href="http://xzl52199.blog.163.com/blog/{$r[url]}">{$r[catname]}</a> |  
  4. {/loop}  
  5. {/pc}  

  显示指定id的栏目名称 (例子这里catid=22)

[php] view plaincopyprint?
  1. {$CATEGORYS[22]['catname']}  

  在文章面前显示文章类别

[php] view plaincopyprint?
  1. {pc:content action="lists" catid="79" order="listorder DESC" num="14" }  
  2. <?php $TYPE = getcache('type_content','commons');?>  
  3. {loop $data $n $r}  
  4. <li>{if $TYPE[$r[typeid]][name]}<span style="color:#CC6600">[ {$TYPE[$r[typeid]][name]}]  
  5.   
  6. </span>{/if}<a href="http://xzl52199.blog.163.com/blog/{$r['url']}"{title_style($r[style])}title="{$r['title']}"  
  7.   
  8. target="_blank">{str_cut($r[title],33,'')}</a></li>  
  9. {/loop}  
  10.   
  11. {/pc}  

  指定变量循环增长(幻灯片经常用到)

[php] view plaincopyprint?
  1. {pc:content action="lists" catid="66" order="listorder DESC" thumb="1" num="5" }  
  2.   
  3. {php $num = 0}  
  4.   
  5. {loop $data $r}  
  6.   
  7. linkarr[{$num}] = "{$r[url]}";  
  8. picarr[{$num}] = "{$r[thumb]}";  
  9. textarr[{$num}] = "{str_cut($r[title],36,'')}";  
  10. {php $num++}  
  11.   
  12. {/loop}  
  13.   
  14. {/pc}  

  文章调用使用limit

[php] view plaincopyprint?
  1. {pc:content action="position" posid="36" num="1" order="listorder DESC limit 1,1--" }  
  2. 其他都是跟以前一样使用  
  3. {pc:content action="position" posid="31" order="listorder DESC" limit='1,8--'}  
  4. {loop $data $r}  
  5. <li><a href="http://blog.csdn.net/lee_magnum/{$r[url]}" title="{$r[title]}" target=_blank>{str_cut($r[title],36,'')}  
  6.   
  7. </a></li>  
  8. {/loop}  
  9. {/pc}  

  文章从指定位置开始调用

[php] view plaincopyprint?
  1. 起始位置为5,调用3条。相当于limit功能。  
  2. {pc:content action="position" posid="27" order="listorder DESC" num="3" start="5"}  
  3. {loop $data $r}  
  4. <a href='http://xzl52199.blog.163.com/blog/{$r[url]}'>{str_cut($r[description],115)}... </a>  
  5. {/loop}  
  6. {/pc}  

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

  注意:explode(',',$r[keywords]);是将文章关键词通过英文逗号分离,也就是说每一篇文章都要以逗号间隔关键字,否则调用出来会 是全部作为一个关键字。如果是空格间隔关键字,将explode(',',$r[keywords]);改成explode(' ',$r[keywords]);

[php] view plaincopyprint?
  1. {pc:content action="lists" catid="$catid" num="10" order="id DESC" page="$page"}  
  2. {loop $data $r}  
  3. <a href="http://xzl52199.blog.163.com/blog/{$r[url]}">{$r[title]}</a>  
  4. {php $keywords = explode(',',$r[keywords]);}  
  5. <b>文章标签:</b>  
  6. {loop $keywords $keyword}  
  7. <a href="http://xzl52199.blog.163.com/blog/{APP_PATH}index.php?m=content&c=tag&catid={$catid}&tag={urlencode($keyword)}"  
  8.   
  9. class="blue"> {$keyword}</a>  
  10. {/loop}  
  11. {/loop}  
  12. {/pc}  

  每当列表几行的时候出现一次某些符号

        比如首页里面的文章推荐,一行显示两条,在这两条中间想加一条竖线 | 就用到这个代码了。

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

  v9 列表页完美支持自定义段调用

[php] view plaincopyprint?
  1. {pc:content action="lists" catid="$catid" num="25" order="id DESC" page="$page" moreinfo="1"}  
  2. {loop $data $r}  
  3. <a href="http://blog.csdn.net/lee_magnum/{$r[url]}">[{$r['字段名']}]> {$r[title]}</a>  
  4. {/loop}  
  5. <div class="pagebar">{$pages}</div>  
  6. {/pc}  

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

  其他代码 该咋地还是要咋地 。这是要素

[php] view plaincopyprint?
  1. {php $arrchildid = $CATEGORYS[$CAT[parentid]][arrchildid]}  
  2. {pc:get sql="SELECT * FROM v9_news where catid in($arrchildid) cache="3600" page="$page" num="12" return="data"}  

  V9表单功能

  提交之后如何返回当前页面,而不是默认的首页文件地址

  找到 phpcms\modules\formguide\index.php文件第73行

[php] view plaincopyprint?
  1. showmessage(L('thanks'), APP_PATH);  

  修改成 如下代码即可实现自动返回前一页

[php] view plaincopyprint?
  1. showmessage(L('thanks'), HTTP_REFERER);  

  v9 首页或分页自定义字段调用

 

  普通列表或栏目调用自定义字段

  在{pc:content action="lists" 后加上副表moreinfo=1 (等于1时显示,0时不显示)

  例子:

[php] view plaincopyprint?
  1. {pc:content action="lists" moreinfo=1 catid="2" order="id DESC" num="4"}  
  2. <ul>  
  3. {loop $data $key $val}  
  4. <li><a href="http://xzl52199.blog.163.com/blog/{$val['url']}">{$val['title']}</a>  
  5. <br>价格:{str_cut($v['自定义段'],100)} //100 是字数  
  6. </li>  
  7. {/loop}  
  8. </ul>  
  9. {/pc}  

  推荐位调用自定义字段

  在模型里加好自定义字段后,必须把“在推荐位标签中调用”点击“是“

  然后用同一样的方法去调节数据就OK了,记住,如果你加了文章,必须去更新文章才会显示,自定义段在

  推荐中只显示你选择后,选择前加的加文章不显示,更新一下文章就显示了

  例子:

[php] view plaincopyprint?
  1. {pc:content action="position" posid="推荐位id" num="30" thumb="1" moreinfo="1" order="listorder DESC"}  
  2. {loop $data $key $val}  
  3. <li>  
  4.     <a href="http://xzl52199.blog.163.com/blog/{$val['url']}" target="_blank">  
  5.         <img src="http://xzl52199.blog.163.com/blog/{$val['自定义段']}" alt="{$val['title']}" height=36 width=98 />  
  6.     </a>  
  7.     <a href="http://xzl52199.blog.163.com/blog/{$val['url']}" target="_blank">{str_cut($val['title'],20)}</a>  
  8. </li>  
  9. {/loop}  
  10. {/pc}  

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

  一: 修改 statics/js/ckeditor/plugins/image/dialogs/image.js

  找到

  accessKey:'T','default':''

  替换成

  accessKey:'T','default':$('#title').val()

  二: 清除浏览器缓存


  增加文章的随机点击数

  找到100行的

[php] view plaincopyprint?
  1. $views = $r['views'] +1  

  修改为:

[php] view plaincopyprint?
  1. $rand_nums=rand(79,186);  
  2.   
  3. $views = $r['views'] + $rand_nums;  

  表示点击一次,增加79到186次不等

  -------------------------------------------------------------

  tips:某些版本出错民间解决方法

  1.缩略图以及图集无法上传

[php] view plaincopyprint?
  1. \phpcms\libs\classes\attachment.class.php  

  请把24行的(也有可能是23行)

[php] view plaincopyprint?
  1. $this->upload_func = 'copy';  

  改成

[php] view plaincopyprint?
  1. $this->upload_func = 'move_uploaded_file';  

  2.碎片模块搜索文章看不到栏目

[php] view plaincopyprint?
  1. phpcms\modules\block\templates\search_content.tpl.php  

  13行改成

[php] view plaincopyprint?
  1. <td><?php  
  2. if(isset($_GET['dosubmit'])){?><div class="rt"><a  
  3. href="javascript:void(0)" onclick="$('#search').toggle()"><?php  
  4. echo L('folded_up_in_search_of')?></a></div><?php }  
  5. echo form::select_category(''$catid'name="catid" id="catid"''',  
  6. '''0', 1)?> </td>  
0 0
原创粉丝点击