想在首页随机调用显示一篇文章或产品,该怎么办呢?

2020-12-01 10:00

想在首页随机调用显示文章或产品,该怎么改呢?需要增加什么代码呢?谢。

注:为了更好的让百度的快照更新。

4621 次浏览 10 条评论 收藏

说说我的看法

登录后可以发表评论 登录
10个评论
-- 楼主 2020-12-01 10:00
可以了,非常感谢!!!
回复
-- 2020-12-01 10:00
改成这样
<!--{nocache}-->
<!--{assign var=\'product\' value=Mod_Product::volist(\"AND v.elite=1\",\"ORDER BY RAND() DESC\",5)}-->
<!--{foreach $product as $volist}-->
<a href=\"<!--{$volist.caturl}-->\"><!--{$volist.catename}--></a>
<a href=\"<!--{$volist.url}-->\"><!--{$volist.productname}--></a>
<!--{/foreach}-->
<!--{/nocache}-->
回复
-- 楼主 2020-12-01 10:00
uknow 发表于 2011-11-28 11:23 static/image/common/back.gif
改成

非常感谢您的耐心解答,不过还是不行,错误改为:
Fatal error: Call to undefined method Mod_Product::product() in C:\\DedeAMPZ\\DedeAMPZ\\WebRoot\\Default\\tpl\\_compiled\\ba45345173c7df1464004a06053fd198ba1c7da2.file.index.tpl.php on line 286
回复
-- 2020-12-01 10:00
<!--{/nocach}-->改成<!--{/nocache}-->
回复
-- 2020-12-01 10:00
168行,闭合标签没写对
<!--{nocache}-->
<!--{/nocache}-->
请检查
回复
-- 楼主 2020-12-01 10:00
wapsky 发表于 2011-11-26 16:39 static/image/common/back.gif
你放在哪里报错?
你放错了地方才知报错吧,
你把调用代码直接放在所需要输出的地方!

我想在首页输出,那是不是应该把这段代码放在index.tpl文件内呢?我怕跟最新产品那的代码有冲突,把最新产品的代码删掉,但还是报错啊。

麻烦了,我是菜鸟

补充内容 (2011-11-28 10:32):
Fatal error: Uncaught exception \'SmartyCompilerException\' with message \'Syntax Error in template \"C:\\DedeAMPZ\\DedeAMPZ\\WebRoot\\Default\\tpl/blue/index.tpl\" on line 168 \"&lt;!--{/nocach}--&gt; \" unknown tag \"nocachclose\"\' in C:\\DedeAMPZ\\DedeAMPZ\\WebRoot\\Default\\source\\core\\sysplugins\\smarty_internal_templatecompilerbase.php:423 Stack trace: #0 C:\\DedeAMPZ\\DedeAMPZ\\WebRoot\\Default\\source\\core\\sysplugins\\smarty_internal_templatecompilerbase.php(248): Smarty_Internal_TemplateCompilerBase->trigger_template_error(\'unknown tag \"no...\', 168) #1 C:\\DedeAMPZ\\DedeAMPZ\\WebRoot\\Default\\source\\core\\sysplugins\\smarty_internal_templateparser.php(2336): Smarty_Internal_TemplateCompilerBase->compileTag(\'nocachclose\', Array) #2 C:\\DedeAMPZ\\DedeAMPZ\\WebRoot\\Default\\source\\core\\sysplugins\\smarty_internal_templateparser.php(2759): Smarty_Internal_Templateparser->yy_r55() #3 C:\\DedeAMPZ\\DedeAMPZ\\WebRoot\\Default\\source\\core\\sysplugins\\smarty_internal_templateparser.php(2859): Smarty_Internal_Templateparser->yy_reduce(55) #4 C:\\DedeAMPZ\\DedeAM in C:\\DedeAMPZ\\DedeAMPZ\\WebRoot\\Default\\source\\core\\sysplugins\\smarty_internal_templatecompilerbase.php on line 423
回复
wapsky 官方认证帐号 2020-12-01 10:00
你放在哪里报错?
你放错了地方才知报错吧,
你把调用代码直接放在所需要输出的地方!
这样不会出错的![s:12]
回复
-- 楼主 2020-12-01 10:00
uknow 发表于 2011-11-25 09:59 static/image/common/back.gif
如果你想随机的产品不进行缓存,应加上
即:
如:随机读取5条推荐产品数据

不好意思,本人是菜鸟,没弄成,下面说一下我的操作:
方式一:直接把您这段代码加在首页\"index.tlpl\"内报错
方式二:把index.tpl内的原有最新产品代码去掉,还是报错。
方式三:把缓存代码去掉还是不行。

我该怎么办呢?
回复
-- 2020-12-01 10:00
如果你想随机的产品不进行缓存,应加上 <!--{nocache}--><!--{/nocache}-->
即:
如:随机读取5条推荐产品数据
<!--{nocache}-->
<!--{assign var=\'product\' value=Mod_Product::product(\"AND v.elite=1\",\"ORDER BY RAND() DESC\",5)}-->
<!--{foreach $product as $volist}-->
<a href=\"<!--{$volist.caturl}-->\"><!--{$volist.catename}--></a>
<a href=\"<!--{$volist.url}-->\"><!--{$volist.productname}--></a>
<!--{/foreach}-->
<!--{/nocach}-->
回复
-- 2020-12-01 10:00
使用函数标签,
请看帖: http://bbs.phpcoo.com/thread-853-1-2.html

如:随机读取5条推荐产品数据
<!--{assign var=\'product\' value=Mod_Product::product(\"AND v.elite=1\",\"ORDER BY RAND() DESC\",5)}-->
<!--{foreach $product as $volist}-->
<a href=\"<!--{$volist.caturl}-->\"><!--{$volist.catename}--></a>
<a href=\"<!--{$volist.url}-->\"><!--{$volist.productname}--></a>
<!--{/foreach}-->
回复
作者信息

5
贴子
0
粉丝
热门贴子

免费试用


咨询热线


在线咨询