有人能帮我吗?
这应该进入功能。php:
function cg_current_user_notification_count() {
$notifications = bp_core_get_notifications_for_user(bp_loggedin_user_id(), \'object\');
$count = !empty($notifications) ? count($notifications) : 0;
echo $count;
}
在要显示它的模板中。
<?php cg_current_user_notification_count(); ?>
资料来源:
https://premium.wpmudev.org/forums/topic/add-buddypress-notifications-to-theme但我得到的错误如下:
致命错误:未捕获错误:调用/Applications/MAMP/htdocs/wp-content/themes/mytheme-child/functions中未定义的函数bp\\u core\\u get\\u notifications\\u for\\u user()。php:18堆栈跟踪:#0
有人能帮我吗?该函数未被弃用,因此这不是问题所在。。。
这里可能有什么问题?
SO网友:Mohammad Anbarestany
use this:
if ( !function_exists( \'bp_core_get_notifications_for_user\' ) ) {
require_once \'/wp-content/plugins/buddypress/bp-core/deprecated/1.9.php\';
}
function cg_current_user_notification_count() {
$notifications = bp_core_get_notifications_for_user(bp_loggedin_user_id(), \'object\');
$count = !empty($notifications) ? count($notifications) : 0;
echo $count;}