Osclass Support Forums
Osclass plugin support => Favorite Items Plugin => Topic started by: wfaiiigy on July 20, 2017, 09:51:02 AM
-
Function for count your favorites
<?php function fi_count_favorites() {
//Lazy function :P
$user_id = osc_logged_user_id();
$lists = ModelFI::newInstance()->getAllFavoriteListsByUserId( $user_id );
foreach($lists as $l) {
$count = count(ModelFI::newInstance()->getActiveFavoriteItemsByListId( $l['list_id'] ));
}
//Fix for blank count
if ($count == ''){
echo $count = 0;
} else {
echo $count;
}
}
?>
Call function to your notification class
<span class="counter"><?php echo fi_count_favorites(); ?></span>
-
@wfaiiigy
Thanks for sharing nice piece of code ;)
-
Good morning!
Function for count your favorites
<?php function fi_count_favorites() {
//Lazy function :P
$user_id = osc_logged_user_id();
$lists = ModelFI::newInstance()->getAllFavoriteListsByUserId( $user_id );
foreach($lists as $l) {
$count = count(ModelFI::newInstance()->getActiveFavoriteItemsByListId( $l['list_id'] ));
}
//Fix for blank count
if ($count == ''){
echo $count = 0;
} else {
echo $count;
}
}
?>
Call function to your notification class
<span class="counter"><?php echo fi_count_favorites(); ?></span>
This function displays the number of lists. :-\ How do I output the number of items from all lists?
-
That does not make sense as 1 item can be in multiple lists.
-
That does not make sense as 1 item can be in multiple lists.
The header shows 2 lists. I need to output the 7 items from the two lists.
-
Cool solution! But do not tell me how to install the counter in the mobile version, for example Veronika theme.... When you try to add code, it is automatically commented....
echo '<li><a href="' . osc_route_url('favorite-lists', array('list-id' => '0', 'current-update' => '0', 'notification-update' => '0', 'list-remove' => '0', 'iPage' => '0')) .'" ><i class="fa fa-heart-o"></i>'.__('Favorite items', 'favorite_items').' <span class="im-user-account-count1"><?php echo fi_count_favorites(); ?></span></a></li>';
-
Updated function to count items for non-logged users as well.
<?php
function fi_count_favorites() {
$user_id = (osc_is_web_user_logged_in() ? osc_logged_user_id() : mb_get_cookie('fi_user_id'));
$lists = ModelFI::newInstance()->getAllFavoriteListsByUserId($user_id);
$count = 0;
foreach($lists as $l) {
$count += count(ModelFI::newInstance()->getActiveFavoriteItemsByListId($l['list_id']));
}
return $count;
}
?>
Usage:
<span class="counter"><?php echo fi_count_favorites(); ?></span>