Home php教程 php手册 phpcms v9 模板标签技巧,标签常用方法

phpcms v9 模板标签技巧,标签常用方法

Jun 13, 2016 am 10:56 AM
phpcms str code make Commonly used intercept Skill method Label title template transfer length gather

phpcms v9模板制作常用代码集合

 

 

 

1.截取调用标题长度

{str_cut($r[title],36,'')} ,后面的引号是为了去掉....


2.格式化时间

调用格式化时间 2011-05-06 11:22:33

{date('Y-m-d H:i:s',$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表单功能 提交之后如何返回当前页面,而不是默认的首页文件地址


    找到 phpcms\modules\formguide\index.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.缩略图以及图集无法上传
    \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行改成

    if(isset($_GET['dosubmit'])){?>
    href="javascript:void(0)" onclick="$('#search').toggle()"> echo L('folded_up_in_search_of')?>
    echo form::select_category('', $catid, 'name="catid" id="catid"', '',
    '', '0', 1)?>
    22、PHPCMS V9的get标签调用

    1、调用本系统单条数据,示例(调用ID为1的信息,标题长度不超过25个汉字,显示更新日期):
    {get sql="select * from phpcms_content where contentid=1" /}
    标题:{str_cut($r[title], 50)} URL:{$r[url]} 更新日期:{date('Y-m-d', $r[updatetime])}
    2、调用本系统多条数据,示例(调用栏目ID为1通过审核的10条信息,标题长度不超过25个汉字,显示更新日期):
    {get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10"}
         标题:{str_cut($r[title], 50)} URL:{$r[url]} 更新日期:{date('Y-m-d', $r[updatetime])}
    {/get}
    3、带分页,示例(调用栏目ID为1通过审核的10条信息,标题长度不超过25个汉字,显示更新日期,带分页):
    {get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10" page="$page"}
         标题:{str_cut($r[title], 50)} URL:{$r[url]} 更新日期:{date('Y-m-d', $r[updatetime])}
    {/get}
    分页:{$pages}
    4、自定义返回变量,示例(调用栏目ID为1通过审核的10条信息,标题长度不超过25个汉字,显示更新日期,返回变量为 $v):
    {get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10" return="v"}
         标题:{str_cut($v[title], 50)} URL:{$v[url]} 更新日期:{date('Y-m-d', $v[updatetime])}
    {/get}
    5、调用同一帐号下的其他数据库,示例(调用数据库为bbs,分类ID为1的10个最新主题,主题长度不超过25个汉字,显示更新日期):
    {get dbname="bbs" sql="select * from cdb_threads where fid=1 order by dateline desc" rows="10"}
         主题:{str_cut($r[subject], 50)} URL:http://bbs.phpcms.cn/viewthread.php?tid={$r[tid]} 更新日期:{date('Y-m-d', $r[dateline])}
    {/get}
    6、调用外部数据,示例(调用数据源为bbs,分类ID为1的10个最新主题,主题长度不超过25个汉字,显示更新日期):
    {get dbsource="bbs" sql="select * from cdb_threads where fid=1 order by dateline desc" rows="10"}
         主题:{str_cut($r[subject], 50)} URL:http://bbs.phpcms.cn/viewthread.php?tid={$r[tid]} 更新日期:{date('Y-m-d', $r[dateline])}
    {/get}

    不知道有没有朋友在使用中遇到这几种方法不能满足需求的时候呢?

    例如:取出评论数最多的第3条到第10条记录,有人说我是多此一举,一般取最多评论没理由不取第一和第二条,因为PHPCMS的缩略图对4:3这样的尺寸比较好,对长条形(如3:4)的图片缩略效果不好,为了自己手动更新评论最多的第一和第二条记录,故此不想自动更新读取前两条。

    关键点就在 order by B.comments desc LIMIT 3,7 (表示从第3条记录开始,向下读取7条数据)这个在MYSQL是经常用,我抱着试试看的想法,结果是可以的。

    效果如下:

     

    希望做PHPCMS开发的朋友共同学习和分享

    phpcms V9 保留了2008的get标签的使用方法

    它包括了2种方式一种是内部数据,另一种是外部数据

    我们先分析下内部数据的使用方法

    1、内部数据的调用

            {pc:get sql="SELECT * FROM `XX` WHERE  fid =$ltid AND digest =2 AND ifupload =1 ORDER BY tid DESC" num="2" cache= "3600" return="data" }
            {loop $data $r}

            。。。。。

          {/loop}{/pc}

    由此可以看出  get 语句支持num的用法但是不支持 limit 5,5.这样的用法

    实在是很遗憾

    num是调用的条数

    2、外部数据的调用

    { pc : get sql = "SELECT * FROM phpcms_member" cache = "3600" page = "$page" dbsource = "discuz" return = "data" }

      { loop $data $key $val }

      { $val [ username ]}

      { /loop}

      ul >

      { $pages }

      {/ pc }

      一个是数据源,一个是产生的pages翻页效果

       

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) May 01, 2024 pm 12:01 PM

    Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

    How to set font size on mobile phone (easily adjust font size on mobile phone) How to set font size on mobile phone (easily adjust font size on mobile phone) May 07, 2024 pm 03:34 PM

    Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

    The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) May 04, 2024 pm 06:01 PM

    Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

    The difference between Go language methods and functions and analysis of application scenarios The difference between Go language methods and functions and analysis of application scenarios Apr 04, 2024 am 09:24 AM

    The difference between Go language methods and functions lies in their association with structures: methods are associated with structures and are used to operate structure data or methods; functions are independent of types and are used to perform general operations.

    A must-have for veterans: Tips and precautions for * and & in C language A must-have for veterans: Tips and precautions for * and & in C language Apr 04, 2024 am 08:21 AM

    In C language, it represents a pointer, which stores the address of other variables; & represents the address operator, which returns the memory address of a variable. Tips for using pointers include defining pointers, dereferencing pointers, and ensuring that pointers point to valid addresses; tips for using address operators & include obtaining variable addresses, and returning the address of the first element of the array when obtaining the address of an array element. A practical example demonstrating the use of pointer and address operators to reverse a string.

    How to choose a mobile phone screen protector to protect your mobile phone screen (several key points and tips for purchasing mobile phone screen protectors) How to choose a mobile phone screen protector to protect your mobile phone screen (several key points and tips for purchasing mobile phone screen protectors) May 07, 2024 pm 05:55 PM

    Mobile phone film has become one of the indispensable accessories with the popularity of smartphones. To extend its service life, choose a suitable mobile phone film to protect the mobile phone screen. To help readers choose the most suitable mobile phone film for themselves, this article will introduce several key points and techniques for purchasing mobile phone film. Understand the materials and types of mobile phone films: PET film, TPU, etc. Mobile phone films are made of a variety of materials, including tempered glass. PET film is relatively soft, tempered glass film has good scratch resistance, and TPU has good shock-proof performance. It can be decided based on personal preference and needs when choosing. Consider the degree of screen protection. Different types of mobile phone films have different degrees of screen protection. PET film mainly plays an anti-scratch role, while tempered glass film has better drop resistance. You can choose to have better

    Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Jun 12, 2024 pm 08:38 PM

    Since the launch of ChatGLM-6B on March 14, 2023, the GLM series models have received widespread attention and recognition. Especially after ChatGLM3-6B was open sourced, developers are full of expectations for the fourth-generation model launched by Zhipu AI. This expectation has finally been fully satisfied with the release of GLM-4-9B. The birth of GLM-4-9B In order to give small models (10B and below) more powerful capabilities, the GLM technical team launched this new fourth-generation GLM series open source model: GLM-4-9B after nearly half a year of exploration. This model greatly compresses the model size while ensuring accuracy, and has faster inference speed and higher efficiency. The GLM technical team’s exploration has not

    Effects of C++ template specialization on function overloading and overriding Effects of C++ template specialization on function overloading and overriding Apr 20, 2024 am 09:09 AM

    C++ template specializations affect function overloading and rewriting: Function overloading: Specialized versions can provide different implementations of a specific type, thus affecting the functions the compiler chooses to call. Function overriding: The specialized version in the derived class will override the template function in the base class, affecting the behavior of the derived class object when calling the function.

    See all articles