I want to take away "Online users" so only this are showing
"Who's online
There is currently 1 user and 1 guest online."
Now it's like this:
Who's online
There is currently 1 user and 1 guest online.
Online users
* name
* name
* name
I think I have to do something her in "user.module", but what?
Thank you for a good sulotion.
case 3:
if (user_access('access content')) {
// Count users with activity in the past defined period.
$interval = time() - variable_get('user_block_seconds_online', 900);
// Perform database queries to gather online user lists. We use s.timestamp
// rather than u.access because it is much faster is much faster..
$anonymous_count = sess_count($interval);
$authenticated_users = db_query('SELECT u.uid, u.name FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= %d AND s.uid > 0 ORDER BY s.timestamp DESC', $interval);
$authenticated_count = db_num_rows($authenticated_users);
// Format the output with proper grammar.
if ($anonymous_count == 1 && $authenticated_count == 1) {
$output = t('There is currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
}
else {
$output = t('There are currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
}
// Display a list of currently online users.
$max_users = variable_get('user_block_max_list_count', 10);
if ($authenticated_count && $max_users) {
$items = array();
while ($max_users-- && $account = db_fetch_object($authenticated_users)) {
$items[] = $account;
}
$output .= theme('user_list', $items, t('Online users'));
}
$block['subject'] = t('Who\'s online');
$block['content'] = $output;
}
return $block;
}
Comments
Don't edit the module file
Don't edit the module file directly. Instead, create a new block, name it Who's Online, change input format to PHP, and paste this into the body:
What if I simply want to remove the text "Online Users" ?
I'd like to leave the list of users in the block, but, it takes up five lines, which is too clunky in my opinion. Right now it looks like this:
Who's online
There are currently 1 user and 0
guests online.
Online users
* Eileen
But I'd like it to look like this:
Who's online
1 user, 5 guests
* Eileen
I've been trying to modify it myself, but it's not working. Any help would be great.
Eileen
css?
In this case, CSS is a much easier way to achieve the same goal.
Find the ID of the 'Who's online' block (on my site it's "block-user-3") and add a rule to your css file like this:
Done!
Thank you for posting how to
Thank you for posting how to modify the online visitors block. I tried it and it works great. I was wondering, though, if there is a way to have it say instead of
Who's online
There is currently 1 user and 1 guest online.
I would rather have it say
Who's online
There are currently 2 people online.
I would like to lump the guest and the users together. Thank you so much for the help that can be found in the forum.
Is there a way of outputting
Is there a way of outputting the online users as (with the comma between them except the last):
"user1, user2, user3, user5"
instead of a list..
user1
user2
user3
user5
yea
yea uneed to do a bit of formatting ....
-- Sree --
IRC Nick: sreeveturi
override template
You would have to override the theme_user_list function (http://api.drupal.org/api/function/theme_user_list/5) by copying the code into your templete.php file and then edit it.
You might end up with something like this (I did't test it, no guarantees!)
When adding this the user
When adding this the user list disappeared...
oops
Sorry, I see the mistake I made, I turned a foreach loop into a for loop but I didn't adjust all code within the {} correctly. Second try, still not tested:
Thanks, I replaced the code,
Thanks, I replaced the code, but it didn't do anything and the user-list is still gone...
I apologize
I should be more careful and precise when I try to help others. It's not much help for you like this. But now I present you: tested, working code. Cheers!
By the way, for the sake of completeness, I should mention that the function name in the first line should be changed, according to your needs, into "[yourtemplateengine]_user_list" or "[yourtemplatename]_user_list". See http://drupal.org/node/55126 for more info.
I still can't see any users
I still can't see any users online....
I'm using the code from http://drupal.org/node/66638 in a block, do I have to change it in order to work with this?
Thanks ;)
I don't know the code in the
I don't know the code in the post you mentioned. The code I gave you is based on the standard Drupal 5 "Who's Online" block. As said, it is added to the template.php file in the folder of my default theme.
Now with profile links
Thank you from almost two years later. ;) My only quibble with the above code is that it removes the links to the user profiles, so I've added them back in. See below:
doesn't quite work
Here's an example that is almost correct. Maybe someone with coding experience can take a look and figure out why it isn't working.
It does combine all visitors into one value. However, when listing the members, it repeats one member for however many members are actually online. This will vary based on which member most recently accessed the site. So for example, it may list "Brad, Brad, Brad," for the three members that are online.
I have limited experience so that's as far as I can take it.
This part of your code will
This part of your code will probably not work:
First of all, the foreach loop runs once for every value in the $items array. Within the loop, you chose $item as variable representing the current value. Therefore the second line should be
$output .= theme('username', $item);
Otherwise, you keep adding the first field of the array ($items[0]) to your output string in every loop.
The third line of your code presents another problem: it only checks if there is more than one user online. However it should check if the last name has already been added to the output. In that case, the comma should not be added. This problem is the reason why I chose a for-loop in the code I posted above (http://drupal.org/node/148911#comment-276478) instead of a foreach-loop. The for-loop is a little more complicated, but it gives you a variable ($i for instance) which helps you to keep track of the number of times the loop has been procesed. You could also create such a variable yourself:
works!
Fantastic, thanks for the help, it works like a charm now. :)
How to add Total of 10
How to add
Total of 10 registered users there are currently 1 user and 0 guests online.
instead of
There are currently 1 user and 0 guests online.?
after this piece of code //
after this piece of code
add this:
Then you can use the $total_count variable in your outputstring.
Avatar
I've always thought it would be cool to display the users Avatar along side their username in this block. Just haven't had the time to work it out.
Anyone else done this?
Dont want users as list
I want to place this block in my footer but the way its layed out is in the list format.
* User1
* User2
* User3
I just want to change the listing of the user to be one after another. how would i do this?
Who's online
There is currently 1 user and 1 guest online
Online Users: User1, User2, User3
Also if possible where each users name links to their profile (if easily done at all)
Looking for Drupal 7 Solution to put user's online for field
I have tried to make this work for drupal 7 to get a who's online filed for ALL users.
Using globals php and views php module, user stats module also.
In the code output I put this code:
<?php print($row->login); ?>
The online users DO show up on my view,
But when logged out, they show as still online...
What is the correct code to put in there so this works?
When adding this the user list disappeared...
When adding this the user list disappeared...
I have 100 users registered
I have 100 users registered in Mysite and they are from different countries. They have also posted their Content.
When they logged in their account, how do I show if they are Online/Offline to other users ?
Any help much appreciated.