PHPCMSV9的相关文章默认需要在后台设置,前台才能正常调用,如果我们没有统一设置相关文章,那怎么来实现相关文章的调用呢。
阅读本文的同时,我假设你的文档均未设置相关文章,调用方法如下:
实现效果如下:
代码于此:
[html]
{php $where = '(title like "%'.join('%" OR title like "%', explode(",", $rs[keywords])).'")';}
{pc:get sql="SELECT * FROM `www.4wei.cn` where catid ='$catid' and $where order by id desc" cache="100" num="5" page=""}
{loop $data $r}
{php $index++}
{if $index < 4}{$index}{else}{$index}{/if}
{/loop}
{/pc}
{if $index < 5}
{pc:get sql="SELECT * FROM `www.4wei.cn` where catid ='$catid' order by id desc" cache="100" num="5" page=""}
{loop $data $r}
{php $index++}
{if $index < 4}{$index}{else}{$index}{/if}
{/loop}
{/pc}
{/if}
{php unset($index);}
{php $where = '(title like "%'.join('%" OR title like "%', explode(",", $rs[keywords])).'")';}
{pc:get sql="SELECT * FROM `www.4wei.cn` where catid <>'$catid' and $where order by id desc" cache="100" num="10" page=""}
{loop $data $r}
{$index++}
{if $index < 4}{$index}{else}{$index}{/if}
{/loop}
{/pc}
[/html]
详解于此:
根据文章的关键字组合模糊搜索SQL
使用PC的Get标签获取数条相关结果
假如相关文章数量不足,再从相同栏目获取数条结果充数
如果你的文章有在后台添加相关文章,如果数量不够,也可以使用这个方法进行补充调用
感谢V9强大的模板标签功能,相信PC会越来越好。