联系官方销售客服
1835022288
028-61286886
在内容页中怎么通过迅搜插件调用相关内容,其实还是比较简单的,直接上代码
1、在要显示相关内容的前面,或者是放在模板最前面,插入一下PHP代码
<?php $this->xsobj = \Phpcmf\Service::L('ZylXunsearch', 'zyl_xunsearch'); $search = $this->xsobj->xs->search; $search->setFuzzy(true); //开启模糊搜索,如果要精确,请设置false $search->setQuery($title); // 设置搜索语句,这里是按标题模糊搜索相关内容,按需修改 $search->setLimit(10); // 设置返回结果最多为 10 条 $docs = $search->search(); $shareCategor = \Phpcmf\Service::M('XunsearchCache', 'zyl_xunsearch')->get_shareCategory(); //获取共享栏目列表 $moduleList = \Phpcmf\Service::M('XunsearchCache', 'zyl_xunsearch')->get_moduleList(); //获取内容模块列表 $lists = []; foreach ($docs as $key => $doc) { $share = $moduleList[$doc->dirname]['share']; if ($share) { $classname = $shareCategor[$doc->catid]['name']; } else { $row = \Phpcmf\Service::M()->table_site($doc->dirname . '_category')->where('id', $doc->catid)->getRow(); $classname = $row['name']; } $classurl = dr_url($doc->dirname . '/category/index', ['id' => $doc->catid]); $titleurl = dr_url($doc->dirname . '/show/index', ['id' => $doc->id]); $lists[] = [ 'title' => $doc->title, 'inputtime' => $doc->inputtime, 'titleurl' => $titleurl, 'classname' => $classname, 'classurl' => $classurl, ]; } ?>
2、在要显示内容的地方,执行以下loop循环
{loop $lists $t} <li> <a href="{$t.titleurl}" title="{$t.title}"> <span class="badge fc-icon-left"> {$key+1} </span> {dr_strcut($t.title, 20)}</a> </li> {/loop}
这样就可以刷新页面查看效果了,当然不仅仅是根据标题,根据关键词、作者等等都是可以的,上面只是一个简单的例子。