search
HomeBackend DevelopmentPHP TutorialPHPCMS2008制造标签以及标签模板

PHPCMS2008制作标签以及标签模板

标签设置教程

我们从简单到复杂

第一种:中文标签

这种再简单不过了,就是通过后台设置标签参数调用

通过选择读取段来进行调用,这里设置都是中文字,我们都是中国人,也就不多说了。

栏目   常用变量表示 $catid   可以用这个变量调用,也可以指定到某个栏目下面,用变量调用,它会根据当前页面的栏目来获取id从而根据你的标签设置条件来进行显示

类别 常用变量表示:$typeid 也一样

地区     常用变量表示:$areaid

缩略图 常用变量表示:$thumb       这个是选择条件,你选择了就是调用图片文章,信息类的

发布人   常用变量表示:$userid       调用指定会员的,也可以在查看某个会员的东西时用到

更新时间   常用变量表示:$updatetime 发布时间   常用变量表示:$inputtime   调用指定某一天的

推荐位   常用变量表示:$posids          推荐位置,在发布文章的时候有推荐位置选择,在这里就可以调用了

排序方式 按ID,时间,浏览次数等等调用,这根据不同的位置选择不同的调用方式。如:排行,就用浏览次数,最新就按发布时间降序

分页显示 调用条数 这个不用说,看字会意就知道了

标签模板 这里是该标签你将要调用哪个标签模板,以什么样的形式调用,新加的标签模板也会显示到这里的。如:我新建的标签模板叫tag_content_w3zz.html,里面保存我要显示的样式,这里就可以选择调用这个模板了

自定义变量   这就是2008的强大之处,连变量我们都可以自己定义了。你想要哪样的变量就定义哪样的,但是你要记得这里的变量就是你标签模板里面用来判断的变量,如:字数,是否显示,链接打开方式,时间格式等等

在这里设置的自定义字段一定要记住,务必要与标签模板里面的对应,否则无显示。

第二种:通过自定义SQL调用

这种只要懂SQL的就应该完全没有问题

现在我以例子来说明怎么写这样的SQL

第一种,调用一个数据表的内容:

如:调用图片栏目的图片

SELECT contentid,title,style,thumb,url FROM `content` WHERE   `status`=99   AND   `thumb`!=''   ORDER BY contentid DESC"

这里我查询了内容ID,标题,样式,缩略图,链接地址这里的字段可以在后台系统设置--系统工具--数据字典里面查看各个数据表的字段加以理解,这里也可以对照,通过后台设置标签参数调用的字段来写

select是PHP查询函数

contentid这些是你要查询出来的东西,如果你要全部查询就用*,把全部字段内容都查询出来

from 'phpcms_content' 这是从数据表'phpcms_content'里面查询,你要查询哪个数据表就写哪个数据表

WHERE   `status`=99   AND   `thumb`!=''   这个是查询条件,status是状态,如:审核通过 AND是连接多个查询条件,是并且的关系,同时满足才可以,还有一个是or是或者,满足多个条件之中的一个就可以了。

ORDER BY contentid DESC 这个是排序方式,这里也可以对照,通过后台设置标签的排序方式就可以了。desc是降序,asc是升序

第二种:查询两个数据表

SELECT a.contentid,a.title,a.style,a.thumb,a.updatetime,b.unit,b.price,a.description,a.inputtime,b.stars,a.url FROM `pc_content` a, `pc_c_product` b WHERE a.contentid=b.contentid AND   `status`=99   AND   `thumb`!=''   ORDER BY a.contentid DESC

其实相对于第一种情况,也差不多,就是对数据表进行处理,同时查询两个表

看懂了第一种,这种也简单,就是将表`pc_content`定义成a,pc_c_product定义成 b,然后分别查询这两个表里面你所需要的字段,如a.contentid,,b.price

a.contentid=b.contentid 条件这个就是这两个表相关的字段,也就是因为这样,所以才用这样的SQL进行相关查询,最重要的也就是这点。可以说这种SQL就是一种相关查询。

标签模板教程

以我新建如图效果的标签模板为例

PHPCMS2008制作标签以及标签模板 - 萧寒 - 回忆录

标签模板的代码:(分析一下标签模板)

{loop $data $n $r}      

循环,很多人拿起就问 $data $n $r这三个参数是什么意义,因为他没有看程序,就单看这里我也不知道是什么意义。所以我看程序了。 $data就是程序通过查询,也就是标签设置里面设置出来的SQL查询出来的结果就以数组的形式保存在这个里面。 $n是列数,08是从第1条开始的,这个与07的有点不同,07的是从0开始的,所以如果下面要写关于这个的判断就得注意了。如:我要隔5条显示一条线的判断就要写成{if $n%5==1}


{/if}. $r就是你将循环出来的值保存的变量,这个和后面的显示就相关了,所以这里的变量一定要注意和后面的对应。

  • {$r[title]}

    显示图片{thumb($r[thumb], $width, $height)}缩略图函数,三个参数分别是,图片,宽度,高度

    {if $r[style]}{str_cut($r[title], $titlelen,'')}{else}{str_cut($r[title], $titlelen,'')}{/if}

    标题显示{if $r[style]}这个判断是判断你添加的时候是否给了样式,就是颜色和加粗,如果有给就按这个样式显示出来,否则就按CSS文件显示。{str_cut($r[title], $titlelen,'')}截取标题,按照我们在自定义字段那里加的titlelen来截取,系统的是{str_cut($r[title], $titlelen)}这样会显示省略号,如果你不想要省略号就用我的这里的。

    {if $showprice}
    ¥{$r[price]}元/{$r[unit]}{/if}{if $showcart}

    显示价格 {if $showprice}判断是否显示 showprice在自定义字段里面设置一个非0的值

    订购产品PHPCMS2008制造标签以及标签模板{/if}

  • 显示购买的那两个图片,链接,这些都参照内容页的购买设置就可以了。

    {/loop}

    结束循环,这个不能少哟,少了就无法更新了,注意完整,在哪里都应该注意

    {if $pages}

    {$pages}

    {/if}

    是否分页显示,这个在标签设置处设置

    其实我就是给默认的产品标签模板加了几个判断显示而已,其它的产品标签同样也可以用我这个显示想要的内容

    我的自定义字段是:

    PHPCMS2008制作标签以及标签模板 - 萧寒 - 回忆录

    这样我的标签就出来了。

    看起来很简单吧

    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
    How can you check if a PHP session has already started?How can you check if a PHP session has already started?Apr 30, 2025 am 12:20 AM

    In PHP, you can use session_status() or session_id() to check whether the session has started. 1) Use the session_status() function. If PHP_SESSION_ACTIVE is returned, the session has been started. 2) Use the session_id() function, if a non-empty string is returned, the session has been started. Both methods can effectively check the session state, and choosing which method to use depends on the PHP version and personal preferences.

    Describe a scenario where using sessions is essential in a web application.Describe a scenario where using sessions is essential in a web application.Apr 30, 2025 am 12:16 AM

    Sessionsarevitalinwebapplications,especiallyfore-commerceplatforms.Theymaintainuserdataacrossrequests,crucialforshoppingcarts,authentication,andpersonalization.InFlask,sessionscanbeimplementedusingsimplecodetomanageuserloginsanddatapersistence.

    How can you manage concurrent session access in PHP?How can you manage concurrent session access in PHP?Apr 30, 2025 am 12:11 AM

    Managing concurrent session access in PHP can be done by the following methods: 1. Use the database to store session data, 2. Use Redis or Memcached, 3. Implement a session locking strategy. These methods help ensure data consistency and improve concurrency performance.

    What are the limitations of using PHP sessions?What are the limitations of using PHP sessions?Apr 30, 2025 am 12:04 AM

    PHPsessionshaveseverallimitations:1)Storageconstraintscanleadtoperformanceissues;2)Securityvulnerabilitieslikesessionfixationattacksexist;3)Scalabilityischallengingduetoserver-specificstorage;4)Sessionexpirationmanagementcanbeproblematic;5)Datapersis

    Explain how load balancing affects session management and how to address it.Explain how load balancing affects session management and how to address it.Apr 29, 2025 am 12:42 AM

    Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

    Explain the concept of session locking.Explain the concept of session locking.Apr 29, 2025 am 12:39 AM

    Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

    Are there any alternatives to PHP sessions?Are there any alternatives to PHP sessions?Apr 29, 2025 am 12:36 AM

    Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

    Define the term 'session hijacking' in the context of PHP.Define the term 'session hijacking' in the context of PHP.Apr 29, 2025 am 12:33 AM

    Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

    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

    Video Face Swap

    Video Face Swap

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

    Hot Tools

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SAP NetWeaver Server Adapter for Eclipse

    SAP NetWeaver Server Adapter for Eclipse

    Integrate Eclipse with SAP NetWeaver application server.