如何在类别内的广告列表中显示自定义字段


How to show custom fields on Ad listing within category

我已经从管理面板添加了自定义字段,它显示在广告的详细信息页面上,但我也想显示在列表页面上,你能告诉我我需要编码的文件、PHP文件、CSS或类文件吗。我不知道PHP编码,但知道.Net。提前感谢!

如果我没有弄错的话,Listing页面就是搜索页面(其中显示项目列表)。

为了做到这一点,您必须在oc-includes/osclass/controller/Search.php中查找searchafter_search挂钩。

您还需要一个DAO对象,本教程应该会让您入门。

osc_add_hook('after_search', function() {
    if (osc_is_search_page()) {
        osc_reset_items();
        while(osc_has_items()) {
            $detail = // Get your discount info for osc_item_id()
            if(isset($detail['fk_i_item_id'])) {
                $result[osc_item_id()] = $detail;
            }
        }
        View::newInstance()->_exportVariableToView("your_plugin_name", $result);
        osc_reset_items();
    }
});

然后,在您的主题搜索.php文件中,您可以使用以下内容检索折扣信息:

$discounts = __get("your_plugin_name");
while(osc_has_items()) {
    $discount = $discounts[osc_item_id()];
}