-
作者帖子
-
我想在論壇裡邊給建立主題的使用者標註 「樓主」,請問哪個函式可以識別 「樓主」?
謝謝!
這個需要具體找找,先提供個思路:
因為 bbPress 的回覆其實就是 WordPress 的評論一種形式,下面是給 WordPress 評論新增管理員表標識的方法,
新增程式碼
在主題檔案內查詢 comments.php 類似的檔案,這個是評論樣式的每個主題都不一樣,然後搜尋找到 $comment->comment_author_email 這樣的文字,在<?php 前面新增以下程式碼。
<?php if(1 == $comment->user_id) { echo '<span class="author-admin"> 管理員</span>'; } ?>
css 樣式
在主題 style.css 檔案的結尾新增以下 css 樣式
.author-admin{font-size:9px;color:#fff;padding:0 4px;background:#c40000;border-radius:2px;vertical-align:super}
針對 bbPress 來說,應該還是需要判斷使用者 ID 和發帖人,晚點在找找詳細方案。
先在 bbPress 原始碼裡找找
bbp-reply-author
、bbp-author-role
相關的函式,好的,多謝,好找了好久了,找不到相關函式。
我自己解決這個問題了,靈感來自 bbpress-private-replies 這款外掛。
把下面程式碼新增到 functions.php 檔案就可以在回覆帖子作者頭像下邊顯示 「樓主」 了,同時,樓主在該主題下回復的帖子,也會樓主兩個字。
function bbp_post_starter( $args = '' ) { $topic_author = bbp_get_topic_author_id(); $reply_author = bbp_get_reply_author_id( $reply_id ); if ( $reply_author === $topic_author ) { ?> <span class="xxx"> 樓主</span> <!--?php <br ?--> } } add_filter('bbp_theme_after_reply_author_details', 'bbp_post_starter');
如果需要修改樣式,可以把上邊函式中的 xxx 換成你的樣式。
看看我的樣式吧:
不錯哦,也是真能折騰。顯示效果也挺好看的。
上邊的程式碼,有個 BUG,在個人檔案中心-> 建立的回覆中,都會顯示 「樓主」,因為你是回覆別人的,肯定不可能是樓主,所以還需要修改一下程式碼。
修改後的程式碼如下:
//新增樓主和非樓主角色 function bbp_post_starter( $args = '' ) { $topic_author = bbp_get_topic_author_id(); $reply_author = bbp_get_reply_author_id( $reply_id ); if ( bbp_is_single_user_replies() ) { } elseif ( $reply_author === $topic_author ) { ?> <span class="post-starter-bq"> 樓主</span> <?php } } add_filter('bbp_theme_after_reply_author_details', 'bbp_post_starter');
-
作者帖子
- 哎呀,回覆話題必需登入。