调用随机文章可以把一些旧的文章,特别是一些比较老的文章,一般应用于网站的首页、列表页、内容页等添加随机文章列表标签等地方展示所有文章,从而让搜索引擎更好的收录文章。
K9调用随机文章标签:
{@res table='%s_content' field='title,url' where="status=1" group='id' number="12"} {#foreach($res as $rs)} <li><a href="{DIR}{$rs[url]}" title="{$rs[title] code='quote'}">{$rs[title]}</a></li> {#endforeach}
如果应用于内容页的话,加上剔除标签id<>{$info['id']},以避免重复数据
- 刷新页面没有变化:group='id'
{@res table='%s_content' field='title,url' where="status=1 and id<>{$info['id']}" group='id' number="12"} {#foreach($res as $rs)} <li><a href="{DIR}{$rs[url]}" title="{$rs[title] code='quote'}">{$rs[title]}</a></li> {#endforeach}
- 每次刷新页面,页面随机变化:order='rand() desc',效果【点击查看】,rand函数用法可查看《mysql使用rand函数随机查询》
{@res table='%s_content' field='title,url' where="status=1 and id<>{$info['id']}" order='rand() desc' number="12"} {#foreach($res as $rs)} <li><a href="{DIR}{$rs[url]}" title="{$rs[title] code='quote'}">{$rs[title]}</a></li> {#endforeach}
以上用法看个人需求调用
转载请注明出处:唯众网络