为 bbPress 论坛添加新贴和置顶帖标签功能。

正在查看 10 个帖子:1-10 (共 10 个帖子)
  • 作者
    帖子
  • 小新
    • 文章数量: 354
    @xiaoxin
    楼主

    非常简单和实用的功能,可以更好的让用户分辨帖子类型 😉 。

    小新
    • 文章数量: 354
    @xiaoxin
    楼主

    新帖子的话两个小时内有提醒是新帖,这样也方便我们分辨进行回复。

    代码如下:

    
    //bbPress 添加置顶标签
    
    function rk_sticky_topics() {
      
       if ( bbp_is_topic_sticky() && !bbp_is_topic_closed() )
          echo '<span class="sticky">[Sticky]</span>';
    }
      
    add_action( 'bbp_theme_before_topic_title', 'rk_sticky_topics' );
    
    //bbPress 添加关闭标签
    function rk_closed_topics() {
      
       if ( bbp_is_topic_closed() && !bbp_is_topic_sticky() )
          echo '<span class="closed">[Closed]</span>';
    }
      
    add_action( 'bbp_theme_before_topic_title', 'rk_closed_topics' );
    
    //bbPress 回复超过 25 个为显示热帖
    
    function rk_hot_topics() {
       $reply_count = bbp_get_topic_reply_count();
      
       if ( $reply_count > 25 )
          echo '<span class="hot">[Hot]</span>';
    }
      
    add_action( 'bbp_theme_before_topic_title', 'rk_hot_topics' );
    jiadexiu
    • 文章数量: 8
    @jiadexiu

    您好请问代码添加到哪里呢?

    诗语
    管理员
    • 文章数量: 5,929
    @feibisi

    将下面的代码片段添加到已激活主题的 functions.php 文件

    lanyueer
    参与者
    • 文章数量: 16
    @lanyueer

    没看到新帖的代码啊

    诗语
    管理员
    • 文章数量: 5,929
    @feibisi

    补充一下,这里,新帖的标签如下。

    //bbPress 添加新话题帖子标签
    function rk_new_topics() {
    $offset = 30*30*1;
    
       if ( get_post_time() > date('U') - $offset )
          echo '<span class="label label-new"> 新帖</span>';
    }
    
    add_action( 'bbp_theme_before_topic_title', 'rk_new_topics' );
    cat
    • 文章数量: 108
    @429456968

    为什么已经标记为 「未解决」 的帖子,过几个小时之后 「未解决」 这个标签就自动消失了呢?请问有办法改成不消失吗。

    诗语
    管理员
    • 文章数量: 5,929
    @feibisi

    本身未解决的这个标签是一个提醒和新帖的类似,我们用的支持插件不一样,默认的论坛没有显示,所以这个有或者没有意义不大。

    cat
    • 文章数量: 108
    @429456968
    //bbPress 添加新话题帖子标签
    function rk_new_topics() {
    $offset = 30*30*1;
    
       if ( get_post_time() > date('U') - $offset )
          echo '<span class="label label-new"> 新帖</span>';
    }
    
    add_action( 'bbp_theme_before_topic_title', 'rk_new_topics' );

    请问这个 30*30 具体代表多少时间呢,假设我想设置新帖时间是 24 小时,怎么设置呢

    诗语
    管理员
    • 文章数量: 5,929
    @feibisi

    拿个简单的比喻来说, 30 分钟 = 1800 秒
    你可以将在上面的内容调整为

    //bbPress 添加新话题帖子标签
    function rk_new_topics() {
    $offset = 1800;
    
       if ( get_post_time() > date('U') - $offset )
          echo '<span class="label label-new"> 新帖</span>';
    }
    
    add_action( 'bbp_theme_before_topic_title', 'rk_new_topics' );

    如果是要一天的话,你可以直接换算成一天的秒数也行。

正在查看 10 个帖子:1-10 (共 10 个帖子)
  • 哎呀,回复话题必需登录。

话题信息

  • 当前位于:bbPress
  • 9 条回复
  • 5 个参与人
  • 最后回复:<a href="https://bbs.weixiaoduo.com/users/feibisi/" title=" 查看诗语的个人资料" class="bbp-author-link"><span class="bbp-author-name"> 诗语</span></a>
  • 上次活动:<a href="https://bbs.weixiaoduo.com/topic/24326/#post-29084" title=" 回复至:为 bbPress 论坛添加新贴和置顶帖标签功能。">6 年、 5 月前</a>