bbpress广告插件修复论坛首页顶部和底部广告

#562

追光
管理员

问题:使用了 [#bbp-topic-index] 短代码来展示论坛首页内容,但 广告在首页不显示 。即使切换到 bbPress 默认的首页模板(如 archive-forum.php),广告仍然不显示,尤其是在以下两个位置:

'adunit_main_header'
'adunit_main_footer'

解决方案:
可以在这个插件的尾部 (靠近 sau_display_ad() 函数后面)添加两个新的 简码(Shortcode) ,用于在页面中手动插入广告单元:

[#bbp_sau_header]:显示 'adunit_main_header' 的广告
[#bbp_sau_footer]:显示 'adunit_main_footer' 的广告

这样你就可以在任何使用短代码的地方(比如页面、文章、或者 [#bbp-topic-index] 所在页面)插入这两个广告位。

// 新增 shortcode 支持:[#bbp_sau_header]
function sau_bbp_sau_header_shortcode() {
    $location = 'adunit_main_header';
    if (sau_is_hidden($location)) {
        return '';
    }
    return sau_display_ad($location);
}
add_shortcode('bbp_sau_header', 'sau_bbp_sau_header_shortcode');

// 新增 shortcode 支持:[#bbp_sau_footer]
function sau_bbp_sau_footer_shortcode() {
    $location = 'adunit_main_footer';
    if (sau_is_hidden($location)) {
        return '';
    }
    return sau_display_ad($location);
}
add_shortcode('bbp_sau_footer', 'sau_bbp_sau_footer_shortcode');

将以下内容插入到你的页面或文章中:


[#bbp_sau_header]

[#bbp-topic-index]

[#bbp_sau_footer]