如何在织梦CMS中使用dede:artlist标签的notypeid属性来过滤栏目内容?

在织梦CMS中,通过为{dede:artlist}标签增加notypeid属性,可以实现对栏目的过滤。

在织梦CMS(DedeCMS)中,dede:artlist标签是一个非常常用的标签,用于在模板中调用文章列表,有时候我们可能会遇到需要排除某些特定栏目的需求,这时候就需要对标签进行扩展和自定义,本文将详细介绍如何在dede:artlist标签中增加notypeid属性来实现栏目过滤的功能。

修改源码

1、打开文件:找到并打开/include/taglib/arclist.lib.php文件。

2、修改函数返回值

在第130行左右的位置,找到以下代码:

“`php

return lib_arclistDone(

$refObj, $ctag, $typeid, $ctag>GetAtt(‘row’), $ctag>GetAtt(‘col’), $titlelen, $infolen,

$ctag>GetAtt(‘imgwidth’), $ctag>GetAtt(‘imgheight’), $listtype, $orderby,

$ctag>GetAtt(‘keyword’), $innertext, $envs[‘aid’], $ctag>GetAtt(‘idlist’), $channelid,

$ctag>GetAtt(‘limit’), $flag,$ctag>GetAtt(‘orderway’), $ctag>GetAtt(‘subday’), $ctag>GetAtt(‘noflag’),

$tagid,$pagesize,$isweight

);

“`

在最后括号的最后加上$ctag>GetAtt('notypeid')

“`php

return lib_arclistDone(

// … (其他参数)

$ctag>GetAtt(‘noflag’),

$tagid,$pagesize,$isweight,$ctag>GetAtt(‘notypeid’)

);

“`

3、修改函数定义

在第168行左右的位置,找到以下代码:

“`php

function lib_arclistDone(&$refObj, &$ctag, $typeid=0, $row=10, $col=1, $titlelen=30, $infolen=160,

$imgwidth=120, $imgheight=90, $listtype=’all’, $orderby=’default’, $keyword=”,

$innertext=”, $arcid=0, $idlist=”, $channelid=0, $limit=”, $att=”, $order=’desc’, $subday=0, $noflag=”,$tagid=”, $pagesize=0, $isweight=’N’) {

// … (函数内容)

}

“`

在括号的最后加上$notypeid=0

“`php

function lib_arclistDone(&$refObj, &$ctag, $typeid=0, $row=10, $col=1, $titlelen=30, $infolen=160,

$imgwidth=120, $imgheight=90, $listtype=’all’, $orderby=’default’, $keyword=”,

如何在织梦CMS中使用dede:artlist标签的notypeid属性来过滤栏目内容?

$innertext=”, $arcid=0, $idlist=”, $channelid=0, $limit=”, $att=”, $order=’desc’, $subday=0, $noflag=”,$tagid=”, $pagesize=0, $isweight=’N’, $notypeid=0) {

// … (函数内容)

}

“`

4、添加条件语句

在同一文件中,找到以下代码:

“`php

$orwheres[] = ‘ arc.arcrank > 1 ‘;

“`

在这行代码之前添加:

“`php

if (!empty($notypeid)) {

$orwheres[] = " and arc.typeid NOT IN (" . GetSonIds($notypeid) . ")";

}

“`

5、保存文件:完成以上修改后,保存文件。

使用方法

在模板文件中使用dede:arclist标签时,可以通过新增的notypeid属性来排除不需要显示的栏目。

{dede:arclist row='6' orderby='pubdate' type='image.' imgwidth='108' imgheight='150' channelid='1' notypeid='9'}

在这个示例中,notypeid='9'表示排除ID为9的栏目及其子栏目。

相关问答FAQs

问题1:如何确保修改后的代码生效?

解答1:确保你的修改已经正确保存,并且服务器上的缓存已经被清除,你可以尝试刷新页面或者重启服务器以确保修改生效,如果仍然不起作用,请检查代码是否有语法错误或遗漏的地方。

问题2:是否可以同时使用typeidnotypeid属性?

解答2:可以的,typeidnotypeid属性是可以同时使用的。typeid用于指定要显示的栏目ID,而notypeid用于排除特定的栏目ID,这样你可以更灵活地控制文章列表的显示内容。

{dede:arclist row='6' orderby='pubdate' type='image.' imgwidth='108' imgheight='150' channelid='1' typeid='2,3,4' notypeid='9'}

在这个示例中,会显示ID为2、3、4的栏目的文章,但排除ID为9的栏目及其子栏目的文章。

“`html

织梦CMS {dede:artlist} 标签使用 notypeid 属性实现栏目过滤示例

织梦CMS {dede:artlist} 标签增加 notypeid 属性实现栏目过滤

以下是一个使用 {dede:artlist} 标签并增加 notypeid 属性来过滤特定栏目的示例代码。

{dede:artlist typeid='1' notypeid='2,3,4' flag='h'}

  • [field:title/]
  • {/dede:artlist}

    代码说明:

    1. {dede:artlist}:这是织梦CMS中用于列出文章列表的标签。
    2. typeid='1':指定要显示的文章属于哪个栏目,我们指定显示栏目ID为1的文章。
    3. notypeid='2,3,4':这是新增的属性,用于排除特定栏目ID的文章,我们排除了栏目ID为2、3、4的文章。
    4. flag='h':这是一个可选的属性,用于指定文章列表的显示格式,我们使用“h”表示以列表形式显示。
    5. [field:arcurl/]:这是动态获取文章URL的标签。
    6. [field:title/]:这是动态获取文章标题的标签。

    通过这种方式,您可以轻松地使用织梦CMS的 {dede:artlist} 标签来实现对特定栏目的过滤。

    “`

    原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/1127078.html

    (0)
    未希的头像未希新媒体运营
    上一篇 2024-10-02
    下一篇 2024-10-02

    发表回复

    您的电子邮箱地址不会被公开。 必填项已用 * 标注

    免费注册
    电话联系

    400-880-8834

    产品咨询
    产品咨询
    分享本页
    返回顶部
    云产品限时秒杀。精选云产品高防服务器,20M大带宽限量抢购  >>点击进入