【问题标题】:Search shows nothing if user types category name in search bar in osclass如果用户在 osclass 的搜索栏中键入类别名称,则搜索不显示任何内容
【发布时间】:2017-06-13 19:22:53
【问题描述】:

我希望这对其他人也有帮助。 如果用户在搜索栏中键入类别/子类别名称,则搜索栏不会显示任何内容。 我知道有一个单独的字段用于选择类别/子类别以及搜索栏,但在我的情况下,我只有一个搜索栏,当我通过输入类别/子类别名称进行搜索时,搜索显示找到 0 个结果即使我在类别/子类别中有项目。 有没有人可以帮我解决问题

【问题讨论】:

    标签: search osclass


    【解决方案1】:

    在 osclass 中仅通过标题和描述进行搜索。如果您将类别名称插入描述中,那么它将按您的意愿工作。

    在你的主题的functions.php文件中,添加到末尾

    <?php
    function endsWith($haystack, $needle)
    {
    $length = strlen($needle);
    
    return $length === 0 || 
    (substr($haystack, -$length) === $needle);
    }
    function mc_addcategory($desc, $catId) {
    $Cat = Category::newInstance()->toRootTree($catId);
    $d = '\n\n  ';
    foreach($Cat as $c) {
    $d = $d . $c["s_name"] .' / ';
    }
    if(endsWith($desc, $d))
    return $desc;
    else return $desc . $d;
    }
    function mc_filter_description($aItem) {
    
        foreach(@$aItem['description'] as $key => $value) {
            $aItem['description'][$key] = mc_addcategory($value,$aItem['catId']);
        }
    
        return $aItem;
    }
    
    osc_add_filter('item_add_prepare_data', 'mc_filter_description');
    osc_add_filter('item_edit_prepare_data', 'mc_filter_description');
    ?>
    

    第 2 步

    当向公众显示描述时,您可能希望从描述中删除添加的文本,并在编辑 hi 的项目时向所有者显示。 你可以用一个函数来做到这一点 把它放在functions.php中的上述代码之前

    <?php
        function mc_hide_categ_in_description($desc, $catId) {
    
        $Cat = Category::newInstance()->toRootTree($catId);
        $d = '\n\n  ';
        foreach($Cat as $c) {
        $d = $d . $c["s_name"] .' / ';
        }
        if(endsWith($desc, $d))
        return str_replace($d,'',$desc);
        else return $desc;
        }
    ?>
    

    并在显示描述的地方调用此函数。看看这里

    How to modify ft_min_word_len=4 to ft_min_word_len=1 so that osclass 3.7.1 can search min 1 character word, instead of 4?

    看看我在哪里调用'removeunderline('来进行描述。

    OBS

    在此之后,您必须通过编辑和保存每个项目来更新数据库中的描述。 如果项目被编辑并且它的类别被用户更改,这将起作用。

    如果管理员进行编辑,并且上述函数无法从 oc-admin/themes/modern... 文件中调用,则上述最后一个函数必须放在 /oc-includes/osclass/helpers/hSearch .php 并从 functions.php 文件中删除。

    【讨论】:

      猜你喜欢
      • 2016-02-07
      • 1970-01-01
      • 2021-01-25
      • 2015-05-14
      • 1970-01-01
      • 2020-12-05
      • 2011-02-08
      • 1970-01-01
      • 2019-11-07
      相关资源
      最近更新 更多