-
作者帖子
-
我想在論壇裏邊給創建主題的用户標註 「樓主」,請問哪個函數可以識別 「樓主」?
謝謝!
這個需要具體找找,先提供個思路:
因為 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');
-
作者帖子
- 哎呀,回覆話題必需登錄。