ClassCMS文章搜索

搜索article模型中标题包含classcms的文章

{$articlelist.modulehash=article}
<?php
$articlelist['where']['title%']='classcms';
?>
{$articles=a($articlelist)}
{loop $articles as $article}
    <a href="{$article.link}">{$article.title}</a><br>
{/loop}

网站增加搜索栏目

  1. 后台模型中增加模型(模型名为”搜索”,标识为”search”,栏目页面增加”栏目页”)
  2. 增加模型后,增加搜索栏目(栏目名为”搜索”,模型为新增的”搜索”模型)
  3. 搜索表单代码(增加到网站显示搜索框的位置):
<form method="get" action="{$.搜索栏目的id.link}">
    <input type="text" name="keyword" value=""><input type="submit" value="搜索">
</form>
  1. 新建search.php文件(对应为搜索模型的栏目页面)
参考代码:
{if isset($_GET['keyword']) && !empty($_GET['keyword'])}
    搜索词:{htmlspecialchars($_GET['keyword'])}<br>

    {$articlelist.modulehash=article}{//搜索article文章模型}
    {$articlelist.page=page}{//开启分页}
    {$articlelist.pagesize=10}{//每页显示10条}

    <?php
    //只搜索标题:
    $articlelist['where']['title%']=htmlspecialchars($_GET['keyword']);
    //同时搜索标题和内容字段
    //$articlelist['where']['1;']=array('title%'=>htmlspecialchars($_GET['keyword']),'content%'=>htmlspecialchars($_GET['keyword']));
    ?>
    {$articles=a($articlelist)}
    {loop $articles as $article}
        <a href="{$article.link}">{$article.title}</a><br>
    {/loop}
{/if}

开启分页后,如需输出分页列表,默认模板中可直接使用{this:pagelist()},

其它模板则参考 :获取分页信息

ClassCMS中,各个模型文章表互相独立,在搜索中只能搜索单一模型或栏目的文章.

© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容