实用的 WordPress ICP 备案许可管理器

为 bbPress 论坛添加” 新贴” 、 「热帖」 和” 置顶帖” 标签功能

转载自薇晓朵技术论坛

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

//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 添加新话题热帖标签
function rk_hot_topics() {
   $reply_count = bbp_get_topic_reply_count();
  
   if ( $reply_count > 25 ) //回复超过 25 个为显示热帖
      echo '<span class="hot">[Hot]</span>';
}
  
add_action( 'bbp_theme_before_topic_title', 'rk_hot_topics' );

//bbPress 添加新话题帖子标签
function rk_new_topics() {
$offset = 30*30*1; //时间间隔,单位为秒

   if ( get_post_time() > date('U') - $offset )
      echo '<span class="label label-new">[New]</span>';
}

add_action( 'bbp_theme_before_topic_title', 'rk_new_topics' );

 

文章没看懂?代码不会用?需要帮助您可以

Geticer的头像

Uncaught Exception: MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
in [no active file] on line 0

Query Monitor