View Full Version : How can I create Friends widget on the home page
Hello,
I need to create a widget on the home page that shows my friends like the widget on my profile. But I don't know how. Can anyone help me with this :)
I just need to know the code that I can use on the widget to show my friends (Maybe limit the friends widget to show 6 friends only).
I attached an image for the widget that I want to create one like it on the home page.
Thanks a lot,
You could show up to 6 random friends like this:
global $vbulletin;
$friends = $vbulletin->db->query_read_slave("SELECT
user.*, userlist.type, userlist.friend
FROM " . TABLE_PREFIX . "userlist AS userlist
INNER JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = userlist.relationid)
WHERE userlist.userid = " . $vbulletin->userinfo['userid'] . " AND userlist.type='buddy' AND userlist.friend='yes'
ORDER BY RAND()
LIMIT 6
");
while ($friend = $vbulletin->db->fetch_array($friends))
{
$output .= '<a href="member.php?u=' . $friend['userid'] . '">' . $friend['username'] . "</a><br />\r\n";
}
Thank you kh99 for your reply. But could you please teach me how to add your code in widget on the home page. Because I created a new HTML static widget and I paste your code into the widget but when I browsed the Home Page I found the widget shows your code as it is. So I replaced the HTML Static widget with PHP Direct Execution widget and when I browsed the Home Page I found the date of today showing up only in the widget.
Can you help me please. I don't know where's the problem.
The php direct execution widget should work. By default the "configure" text area has a sample line of code that displays the date. You need to make sure you remove that.
Hi kh99,
You are absolutely right. I used php direct execution widget and I replaced the code for the date with your code and the widget works fine now. But is there any chance to list the names of my friends with their profile photos as in the friends widget in my profile (see the attached image in the first post)??
I've started working on something like that. Hopefully it won't take too long (and hopefully I'll actually finish :) ).
A million thanks to you Kh99. I wish you best of luck with the developing of this widget.
I'll keep monitoring your progress with joy!
s_cocis
11-14-2012, 04:43 PM
very good !
CAG CheechDogg
09-30-2013, 05:07 AM
To show all your friends online in a widget you would use this:
global $vbulletin;
if (!$vbulletin->userinfo['userid'])
{
}
else
{
$datecut = TIMENOW - $vbulletin->options['cookietimeout'];
$buddys = $vbulletin->db->query_read("
SELECT
user.username, user.userid, user.lastactivity
FROM " . TABLE_PREFIX . "userlist AS userlist
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = userlist.relationid)
WHERE userlist.userid = {$vbulletin->userinfo['userid']} AND userlist.relationid = user.userid AND type = 'buddy' AND user.lastactivity > $datecut
ORDER BY username ASC
");
$output = '';
while ($buddy = $vbulletin->db->fetch_array($buddys))
{
$output .= ' <a href="member.php?' . $buddy['userid'] . '"> ' . $buddy['username'] . '</a> ';
}
if ($output != '')
{
/*$output = '<font color=#ff0000>Friends Online:</font>' . $output;*/
$template_hook['navtab_end'] .= '
';
}
}
If you see this kh99 would you be kind enough my Man to modify it so that it shows the markups to show the different user groups and comma list after each member ?
lol, I guess I never did finish this. Anyway, I haven't tried it but I think something like this should work:
global $vbulletin;
if (!$vbulletin->userinfo['userid'])
{
}
else
{
$datecut = TIMENOW - $vbulletin->options['cookietimeout'];
$buddys = $vbulletin->db->query_read("
SELECT
user.username, user.userid, user.lastactivity, user.usergroupid, user.displaygroupid
FROM " . TABLE_PREFIX . "userlist AS userlist
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = userlist.relationid)
WHERE userlist.userid = {$vbulletin->userinfo['userid']} AND userlist.relationid = user.userid AND type = 'buddy' AND user.lastactivity > $datecut
ORDER BY username ASC
");
$output = '';
$separator = '';
while ($buddy = $vbulletin->db->fetch_array($buddys))
{
fetch_musername($buddy);
$output .= $separator . '<a href="member.php?' . $buddy['userid'] . '">' . $buddy['musername'] . '</a> ';
$separator = ', ';
}
if ($output != '')
{
/*$output = '<font color=#ff0000>Friends Online:</font>' . $output;*/
$template_hook['navtab_end'] .= '
';
}
}
CAG CheechDogg
09-30-2013, 03:29 PM
I am gonnah cry from joy! lol ...Works great kh99 thank you once again !
Just a quick note, you must include at the very top of the code the following if not the widget will not show up.
global $vbulletin;
Just a quick note, you must include at the very top of the code the following if not the widget will not show up.
global $vbulletin;
Thanks, I added it above. I guess I missed it when I copy/pasted the code.
CAG CheechDogg
09-30-2013, 04:14 PM
Yeerp, thank you kh99 once again my Man you rock!
jimsflies
10-24-2013, 10:21 AM
Could this be turned into a forum block too? If so, how?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.