View Full Version : How to show a module only to visitors?
laminedj
11-03-2013, 02:52 PM
Hello,
I want to show a "Sign up" image in a module on right sidebar only to visitors and a "Welcome" message if it's a registered user.
I know I have to ad a PHP module on right sidebar ad php code.
I found this, as base of work, but I am still blocked
<?php
if (is_member_of(vB5_User::get('usergroupid'), 6)) {
echo "Hi Admin";
} else {
echo "Hello!!!!!!";
}
?>
I am limited on php, little help would be very appreciated.
Regards
Laminedj
Lynne
11-03-2013, 04:08 PM
if (!vB5_User::get('userid') OR vB5_User::get('userid')==0) {
echo '<img src="image.png" alt="sign up" />';
} else {
echo '<span style="color: red;">This is a welcome message</span>';
}
change to suit your needs
laminedj
11-03-2013, 07:11 PM
Thanks Lynne, for your quick response.
If rgister user ID id "two" , I have to replace by '2' in your code?
For "else"
If I want to welcome a registred user with his name and pic, what syntax I have to use ?
Regards
Lynne
11-04-2013, 03:40 AM
I don't understand the question about userid 2. My first line is regarding users with NO userid - they are unregistered.
As for the name, I believe that would be
vB5_User::get('username')
avatar is possibly:
$api->callApi('user', 'fetchAvatar', array('userid' => vB5_User::get('userid')))
(Never tried it, just grabbed it out of the code)
laminedj
11-04-2013, 08:00 AM
Sorry for misunderstand about userid 2, now I get it.
I applied you code for pic and message and it works very well.
For the code for registered users (show name and avatar) I put this, but I doesn' work:
if (!vB5_User::get('userid') OR vB5_User::get('userid')==0) {
echo '<img src="/images/misc/signup.png" alt="sign up" />';
} else {
echo 'vB5_User::get('username') <span style="color: red;">This is a welcome message</span>' vB5_User::get('username') $api->callApi('user', 'fetchAvatar', array('userid' => vB5_User::get('userid');
}
Lynne
11-04-2013, 10:52 PM
I just played with it and got the avatar to work. You will need to format it (image size, change message, etc.) yourself:
$avatar = vB_Api::instanceInternal('user')->fetchAvatar(vB5_User::get('userid'));
$user['avatarpath'] = $avatar['avatarpath'];
if (!vB5_User::get('userid') OR vB5_User::get('userid')==0) {
echo '<img src="http://fansfoot.com/forum/images/misc/signup.png" alt="sign up" />';
} else {
echo '<img src="'. $user['avatarpath'] .'" />';;
}
laminedj
11-05-2013, 02:58 PM
Hello,
I got it, thanks :up: How can add also user name for register members ?
--------------- Added 1383668387 at 1383668387 ---------------
I tried to change the pic size to 50px by 50px , but id didn't work. any idea?
$avatar = vB_Api::instanceInternal('user')->fetchAvatar(vB5_User::get('userid'));
$user['avatarpath'] = $avatar['avatarpath'];
if (!vB5_User::get('userid') OR vB5_User::get('userid')==0) {
echo '<img src="/images/misc/signup.png" alt="sign up" />';
} else {
echo '<span style="color: red; height:50px; width:50px;">Welcome back!</span>';
echo '<img src="'. $user['avatarpath'] .'width="50" height="50" " />';;
}
Lynne
11-05-2013, 08:45 PM
$avatar = vB_Api::instanceInternal('user')->fetchAvatar(vB5_User::get('userid'));
$user['avatarpath'] = $avatar['avatarpath'];
if (!vB5_User::get('userid') OR vB5_User::get('userid')==0) {
echo '<img src="/images/misc/signup.png" alt="sign up" />';
} else {
echo '<span style="color: red; height:50px; width:50px;">Welcome back,'. vB5_User::get('username') .'!</span>';
echo '<img src="'. $user['avatarpath'] .'" width="50" height="50" />';
}
laminedj
11-07-2013, 09:48 AM
Thanks, all is working now!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.