search
HomeBackend DevelopmentPHP Tutorial PHPCMS2008制造标签以及标签模板

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
    The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

    What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

    PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

    PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

    PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

    PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

    PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

    PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

    Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

    PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

    PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

    PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

    PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

    PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

    How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

    PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

    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

    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.

    MantisBT

    MantisBT

    Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool