search
HomeBackend DevelopmentPHP Tutorialphpcms v9 template tag skills, common methods of tags_PHP tutorial
phpcms v9 template tag skills, common methods of tags_PHP tutorialJul 14, 2016 am 10:10 AM
phpcmsstrcodemakeCommonly usedinterceptSkillmethodLabeltitletemplatetransferlengthgather

A collection of commonly used codes for phpcms v9 template production

1. Intercept the call title length

{str_cut($r[title],36,'')}, the following quotation marks are to remove....


2.Formatting time

Call formatting time 2011-05-06 11:22:33

{date('Y-m-d H:i:s',$r[inputtime])}

3. Calling multiple columns & calling multiple recommendations

Calling requirements: The article ranges from three columns: 59, 60, and 61, and is pushed to two recommendation positions: 27 and 28;
Starting from the third article, 7 articles are called continuously.

{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. Display the column name (just the name, without link)

    {$catname}
    Show column name and link (can be clicked)

    {$CATEGORYS[$r['catid']]['catname']}
    5. Get the parent column id/get the parent column name

    {$CATEGORY[$catid][parentid]}
    Parent column name: {$CATEGORYS[$CAT[parentid]][catname]}
    6. External data source call

    dedecmsdb is added at the background data source
    {pc:get sql="SELECT * FROM cq_member where mtype='enterprise' " cache="3600" dbsource="dedecmsdb" num="7" return="data"}
    {loop $data $r}
    {str_cut($r[uname], 28,'')}
    {/loop}
    {/pc}
    7. Call sub-column (need to be used in the column homepage template)

    {pc:content action="category" catid="$catid" num="25" siteid="$siteid" order="listorder ASC"}
    {loop $data $r}
    {$r[catname]} |
    {/loop}
    {/pc}
    8. Display the column name of the specified id (example here catid=22)

    {$CATEGORYS[22]['catname']}
    9. Display the article category in front of the article

    {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. Specify variable cyclic growth (often used in slides)

    {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. Use limit

    when calling articles

    {pc:content action="position" posid="36" num="1" order="listorder DESC limit 1,1--" }
    Use everything else as before
    {pc:content action="position" posid="31" order="listorder DESC" limit='1,8--'}
    {loop $data $r}

  • {str_cut($r[title],36,'')}

  • {/loop}
    {/pc}
    12. The article is called from the specified position

    The starting position is 5, and 3 calls are made. Equivalent to the limit function.
    {pc:content action="position" posid="27" order="listorder DESC" num="3" start="5"}
    {loop $data $r}
                                                                                                                                                                       {/loop}
    {/pc}
    13. Call keywords on the article list page, or call keywords on the homepage


    注意: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’s get tag call

    1. Call a single piece of data from this system, example (call the information with ID 1, the title length does not exceed 25 Chinese characters, and display the update date):
    {get sql="select * from phpcms_content where contentid=1" /}
    Title: {str_cut($r[title], 50)} URL: {$r[url]} Update date: {date('Y-m-d', $r[updatetime])}
    2. Call multiple pieces of data from this system, example (call 10 pieces of information that have been reviewed with column ID 1, the title length does not exceed 25 Chinese characters, and the update date is displayed):
    {get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10"}
    Title: {str_cut($r[title], 50)} URL: {$r[url]} Update date: {date('Y-m-d', $r[updatetime])}
    {/get}
    3. With paging, example (call 10 pieces of information that have passed the review with column ID 1, title length not exceeding 25 Chinese characters, display update date, with paging):
    {get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10" page="$page"}
    Title: {str_cut($r[title], 50)} URL: {$r[url]} Update date: {date('Y-m-d', $r[updatetime])}
    {/get}
    Pagination: {$pages}
    4. Customize the return variable, example (call the 10 pieces of information that have passed the review with the column ID 1, the title length does not exceed 25 Chinese characters, the update date is displayed, the return variable is $v):
    {get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10" return="v"}
    Title: {str_cut($v[title], 50)} URL: {$v[url]} Update date: {date('Y-m-d', $v[updatetime])}
    {/get}
    5. Call other databases under the same account, example (calling database is bbs, the 10 latest topics with category ID 1, the topic length does not exceed 25 Chinese characters, and the update date is displayed):
    {get dbname="bbs" sql="select * from cdb_threads where fid=1 order by dateline desc" rows="10"}
    Subject: {str_cut($r[subject], 50)} URL: http://bbs.phpcms.cn/viewthread.php?tid={$r[tid]} Update date: {date('Y-m-d' , $r[dateline])}
    {/get}
    6. Call external data, example (call the data source is bbs, the 10 latest topics with category ID 1, the topic length does not exceed 25 Chinese characters, and the update date is displayed):
    {get dbsource="bbs" sql="select * from cdb_threads where fid=1 order by dateline desc" rows="10"}
    Subject: {str_cut($r[subject], 50)} URL: http://bbs.phpcms.cn/viewthread.php?tid={$r[tid]} Update date: {date('Y-m-d' , $r[dateline])}
    {/get}

    I wonder if any friends have encountered when these methods cannot meet their needs?

    For example: Take out the 3rd to 10th records with the most comments. Some people say that I am unnecessary. Generally, there is no reason not to take the first and second records with the most comments, because the thumbnails of PHPCMS are like 4:3. The size is better, but the thumbnail effect is not good for long strips (such as 3:4). In order to manually update the first and second records with the most comments, I don't want to automatically update and read the first two records.

    The key point is order by B.comments desc LIMIT 3,7 (meaning starting from the 3rd record, reading 7 pieces of data downwards) This is often used in MYSQL, I had the idea of ​​​​trying it, and the result It is possible.

    The effect is as follows:

    I hope friends who are doing PHPCMS development can learn and share together

    phpcms V9 retains the usage method of get tag in 2008

    It includes 2 methods, one is internal data and the other is external data

    Let’s first analyze how to use internal data

    1. Calling internal data

    {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}

    It can be seen that the get statement supports the usage of num but does not support limit 5, 5. Such usage

    It’s really a pity

    num is the number of calls

    2. Calling external data

    { 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 }

      One is the data source, and the other is the generated page turning effect

      www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477557.htmlTechArticleCollection of commonly used codes for phpcms v9 template production 1. Intercept the calling title length {str_cut($r[title],36, )}, the following quotation marks are to remove.... 2. Format time calls format time 2011-05-06 1...
    Statement
    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
    phpcms是什么框架phpcms是什么框架Apr 20, 2024 pm 10:51 PM

    PHP CMS 是一种基于 PHP 的开源内容管理系统,用于管理网站内容,其特点包括易用性、强大功能、可扩展性、安全性高和免费开源。它可以节省时间、提升网站质量、增强协作并降低开发成本,广泛应用于新闻网站、博客、企业网站、电子商务网站和社区论坛等各种网站。

    phpcms怎么跳转到详情页phpcms怎么跳转到详情页Jul 27, 2023 pm 05:23 PM

    phpcms跳转到详情页方法:1、使用header函数来生成跳转链接;2、循环遍历内容列表;3、获取内容的标题和详情页链接;4、生成跳转链接即可。

    微信登录集成指南:PHPCMS实战微信登录集成指南:PHPCMS实战Mar 29, 2024 am 09:18 AM

    标题:微信登录集成指南:PHPCMS实战在今天的互联网时代,社交化登录已经成为网站必备的功能之一。微信作为国内最流行的社交平台之一,其登录功能也被越来越多的网站所采用。本文将介绍如何在PHPCMS网站中集成微信登录功能,并提供具体的代码示例。第一步:注册微信开放平台账号首先,我们需要在微信开放平台上注册一个开发者账号,申请相应的开发权限。登录[微信开放平台]

    2023年最新phpcms视频教程推荐(二次开发必学)2023年最新phpcms视频教程推荐(二次开发必学)Oct 25, 2019 pm 03:45 PM

    很多站长使用PHPCMS进行二次开发建站,PHP中文网特意推出了phpcms视频教程,大家可以随时随地免费观看视频教程,不需要从百度网盘下载,非常方便。

    phpcms用什么数据库phpcms用什么数据库Feb 21, 2023 pm 06:57 PM

    phpcms用mysql数据库。phpcms是一个PHP开源网站管理系统,采用PHP+MYSQL做为技术基础进行开发。PHPCMS V9采用OOP方式进行基础运行框架搭建,支持的PHP版本是PHP5及以上、支持的MYSQL版本是MySql 4.1以上版本。

    phpcms有评论功能吗phpcms有评论功能吗Feb 16, 2023 am 10:06 AM

    phpcms有评论功能。phpcms内置评论模块,提供了让网站的浏览者发布自己见解的功能,使得浏览者可以互动,相互交流自己的看法,来增加网站人气。PHPCMS的评论用户留言的功能,同时还增加了审核功能,防止言论中出现违禁词汇等。对网站管理者而言,PHPCMS的评论模块可以方便的管理用户评论,可以根据时间、关键字、是否审核等条件查找并管理留言内容。

    phpcms怎么实现微信登陆phpcms怎么实现微信登陆Mar 09, 2023 am 09:33 AM

    phpcms实现微信登录的方法:1、在根目录新建“wechat.php”;2、在“\phpcms\modules\member\index.php”下增加“public function wechat() {...}”;3、在“foreground.class.php”文件中通过wechat函数判断用户是否登录即可。

    phpcms怎么修改站点名称phpcms怎么修改站点名称Feb 24, 2023 am 09:29 AM

    phpcms修改站点名称的方法:1、使用管理员登录后台页面;2、在顶部的菜单栏找到“设置”选项单击,然后在左侧的菜单出找到“站点管理”;3、找到需要修改的站点,点击该站点域名右面的修改链接;4、在弹出的窗口中修改站点名称即可。

    See all articles

    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

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    Repo: How To Revive Teammates
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island Adventure: How To Get Giant Seeds
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    mPDF

    mPDF

    mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

    SublimeText3 Linux new version

    SublimeText3 Linux new version

    SublimeText3 Linux latest version

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools