dedecms arclistsg typeid 栏目ID实现调用动态参数

| | Comments (0)



今天很兴奋阿,困扰了三天的问题终于被我找到了解决方法,舒服啊。这个方法适合arclistsg或者arclist中给typeid赋动态值,当然根据自己需要可以随意赋值给你任何想要的参数。

问题描述:

{dede:arclistsg row='10' titlelen='46' typeid='动态值'}
.....
{/dede:arclistsg}

由上面可以看出,在这个语法中,我需要typeid调用的是一组动态变量,这个变量是在dedecms 模块中的自定义字段,例如 newid,一般new在模板中的调用方法是{dede:field.newid/},但是一旦放入arclistsg中,

{dede:arclistsg row='10' titlelen='46' typeid='{dede:field.newid/}'}
.....
{/dede:arclistsg}

生成静态页面时是无效的,dedecms系统把{dede:field.newid/}看作一串字符串,并不能获得正确想要值。解决终于找到了,查了一些资料,这个方法最简单,如下:

只需要改标签arclistsg.lib.php或者arclist.lib.php文件的代码就行,文件位置include/taglib/中。

由于变量是field,因此我定义如下dede:field.fieldname的形式,如果属性值符合这种形式,就从Fields中取得field的值作为属性值。代码如下:

if (strstr($typeid, "dede:field.")) {
           $newid = substr($typeid, 11);
           $typeid = $refObj->Fields[$newid];
            }

注意newid是模块中自己的自定义字段的数据字段名,可以是任何英文字母组成,长度大小都不影响这段代码。这其中用到两个php 函数 substr() strstr(),用法请参阅链接。为什么说自定义字段的数据字段名长度不影响,原因在于substr($typeid, 11)这句,从11个字符开始后面全取,呵呵,因此你懂得。

这段代码插到哪里,在arclistsg.lib.php文件中查找if(empty($typeid),在这条语句上面插入即可,只是对$typeid多一个判断而已,仅此,好了,我也是 网上看来得,自己整理共享下,好东西分享给大家。还有一个不明白的$refObj这个是dedecms的什么东西。function中定义的,有空再深入学习下,不想花过多时间,半小时没有了,转载给个链接吧,帅哥。

单点日志: http://spoint.babyshoot.cn/archives/2011/08/dedecms-arclistsg-typeid.html

Leave a comment


Type the characters you see in the picture above.

Archives

Ads by google

Pages

Powered by Movable Type 4.24-en

About this Entry

This page contains a single entry by 单点日志 published on August 26, 2011 11:37 PM.

PHP搜索字符串函数 strstr() was the previous entry in this blog.

CSS背景图片添加超链接 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.