View Full Version : Displaying Username
rightworks
02-11-2010, 12:36 AM
Instead of displaying the user avatar, I want to display a simple Welcome Username if the user is logged in. What is the global variable to do that?
This should work for you:
if ($h->currentUser->loggedIn) { echo $h->currentUser->name; }
Nick can you be more specific where does one change that setting,
in which templetes.php? it will be nice that way the user can see the welcome or they will get confused.
Nick can you be more specific where does one change that setting,
in which templetes.php? it will be nice that way the user can see the welcome or they will get confused.
$h->currentUser contains information about the user. You can use it anywhere you like.
rightworks
02-11-2010, 04:17 AM
Taking the code that Nick already has in the theme with what he posted here I now have this:
if ($h->currentUser->loggedIn) {
$id = $h->lang["user_man_username"];
echo "<li>Welcome " . $h->currentUser->name . " ~ </li>";
} ?>
rightworks
02-11-2010, 04:19 AM
In that same code in navigation.php there is a plugin hook to navigation. Where is the navigation hook code. It's a small thing, but I want to change Submit to Submit an Article?
The site is coming around. http://news.massroundup.com
1. Copy /content/plugins/submit/languages/submit_language.php into the languages folder in your theme folder
2. Edit line 88 in the copied file:
/* Navigation */
$lang['submit_submit_a_story'] = "Submit";
Your submit_language.php file will override the original one.
baadier
02-11-2010, 01:10 PM
In that same code in navigation.php there is a plugin hook to navigation. Where is the navigation hook code. It's a small thing, but I want to change Submit to Submit an Article?
The site is coming around. http://news.massroundup.com
Are you developinhg a template from scratch or modifying one of the existing templates? Either way its starting to lookl cool and will blend in with the rest of your site
rightworks
02-11-2010, 01:42 PM
I am just modifying the default template.
runnertalk
02-20-2010, 01:23 PM
How do I display the username as a link to the users profile? I would also like to know how to make a link to the page were users can edit their account.
<a href="<?php echo $h->url(array('user' => $username)); ?>"><?php echo $username; ?></a>
<a href="<?php echo $h->url(array('page' => 'account', 'user' => $username)); ?>"><?php echo $username; ?></a>Replace $username for whichever variable is holding the user's name.
apfind
05-16-2010, 01:49 AM
Thank you Rightworks for this code.
In case anyone wants to show both the icon and show the user name:
Go to navigation.php in your theme.
Replace:
<?php if ($h->currentUser->loggedIn) {
if($h->isActive('avatar')) {
$h->setAvatar($h->currentUser->id, 16);
echo $h->linkAvatar();
}
}
?>
With:
<ul class="navigation">
<?php if ($h->currentUser->loggedIn) {
if($h->isActive('avatar')) {
$h->setAvatar($h->currentUser->id, 16);
echo $h->linkAvatar();
}
}
if ($h->currentUser->loggedIn) {
$id = $h->lang["user_man_username"];
echo "<li>Welcome " . $h->currentUser->name . " </li>";} ?>
But, here's where I have been stumbling for the last hour or two... I also want it to link to the user page. When I try to insert Nick's code from his post, everything under the headline goes blank... I tried lots of different variations but no dice... I even tried to copy some of the code into the code for the other buttons but got rejected everytime! hahahaha :cool:
First, this line serves no purpose, so you can get rid of it:
$id = $h->lang["user_man_username"];@apfind, you're probably mixing the two ways of outputting stuff. Compare these lines:
<a href="<?php echo $h->url(array('user' => $username)); ?>"><?php echo $username; ?></a>
<?php
echo "<a href='" . $h->url(array('user' => $username)) . "'>" . $username . "</a>";
?>We usually use the first in templates because templates are mostly HTML. The second is usually used in plugin files, where most of the code is PHP.
In your case, I think you want to do this:
<?php if ($h->currentUser->loggedIn) { ?>
<li>
Welcome
<a href="<?php echo $h->url(array('user' => $h->currentUser->name)); ?>">
<?php echo $h->currentUser->name; ?>
</a>
</li>
<?php } ?>I've spread that out a bit for the sake of clarity.
apfind
05-16-2010, 03:49 AM
Woooo hoooo! This forum emails you when you get a response! It's like Christmas! :) :) Thank you Nick!!! Apologies for always getting so excited! But, thank you a million times. After searching hard and experimenting for an answer. When it just pops on the screen like this, it's a revelation. Anyways thanks again!
Woooo hoooo! ...Apologies for always getting so excited!
Not at all, it's yelps of joy that make helping so much fun. :D
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.