如果计数大于0(PHP),如何更改类?

时间:2016-10-15 13:09:25

标签: php wordpress class count buddypress

我是一个WordPress网站,我尝试对buddypress实施一些修改。 我最近成功地在主菜单中显示了通知,但是如果计数大于0,我想要更改一些颜色。

所以:如果该值(可能是$ notif?)高于0,则该类" pending-count"必须改为" pending-count-alert" ...

如果你能帮助我......提前致谢!

<?php

function my_nav_menu_notif_counter($menu) {      
        if (!is_user_logged_in())
                return $menu;
        else
                $notif = '<li ><a class="ab-item" href="' . bp_core_get_user_domain(bp_loggedin_user_id() ) . 'notifications/">'. __('').'<span id="ab-pending-notifications" class="pending-count alert">'. __(''). bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) .'</span> </a></li>';
                $menu = $menu . $notif;
                return $menu;
}
add_filter( 'wp_nav_menu_items', 'my_nav_menu_notif_counter' );
add_filter( 'show_admin_bar', '__return_false' );
?>

1 个答案:

答案 0 :(得分:0)

尝试以下内容:

$unreadNotificationCount = bp_notifications_get_unread_notification_count( bp_loggedin_user_id() );
$notif = '<li ><a class="ab-item" href="' . bp_core_get_user_domain(bp_loggedin_user_id() ) . 'notifications/">'. __('').'<span id="ab-pending-notifications" class="' . ( $unreadNotificationCount > 0 ? 'pending-count-alert' : 'pending-count' ) .' alert">'. __(''). $unreadNotificationCount .'</span> </a></li>';