Jump to content
TNG Community
moreisbetter

Display username after login?

Recommended Posts

moreisbetter

I'm using Template 5, and I would like for TNG to display the username at the top of every page while they are logged in.

Has anyone added this feature to their TNG site? I couldn't find it by searching the forums or the Wiki.

Thanks,

Cyndi

Share this post


Link to post
Share on other sites
satyricon

I have added this to my main index page, but not to each page. I am not using a template. When not logged in it shows 'Visitor', when you are logged in it shows the user's name as defined in the user table. Have a look and if it's approaching what you want I'll post the code - http://bedwas.info

Regards

Adrian

Share this post


Link to post
Share on other sites
Ken Roy

I'm using Template 5, and I would like for TNG to display the username at the top of every page while they are logged in.

Has anyone added this feature to their TNG site? I couldn't find it by searching the forums or the Wiki.

Thanks,

Cyndi

Cyndi,

You will need to change topmenu.php and replace line 49

           <td> </td>
with the the following code, which is similar to that used in template 4 or 6
           <td> 
       <?php
    if( $currentuser ) {
        echo "<span class=\"whiteheader\">  $text[welcome], $currentuserdesc.</span>\n";
    }
    else {
        echo "<span class=\"whiteheader\">  $text[welcome], $text[myguest].</span>\n";
    } ?>
  </td>  
You will also need to add the following to your cust_text.php in each language folder
$text[myguest] = "Visitor";

Don't forget to document your changes in another file, so you can redo the changes if needed in the future.

Share this post


Link to post
Share on other sites
moreisbetter

I have added this to my main index page, but not to each page. I am not using a template. When not logged in it shows 'Visitor', when you are logged in it shows the user's name as defined in the user table. Have a look and if it's approaching what you want I'll post the code - http://bedwas.info

Regards

Adrian

Thanks, Adrian! Yes, I would like to see the code for this.

Cyndi

You will also need to add the following to your cust_text.php in each language folder

$text[myguest] = "Visitor";

Thanks, Ken! Do I need to create a user 'myguest'?

Thanks,

Cyndi

Share this post


Link to post
Share on other sites
Ken Roy

Thanks, Adrian! Yes, I would like to see the code for this.

Cyndi

Thanks, Ken! Do I need to create a user 'myguest'?

Thanks,

Cyndi

Cyndi,

$text[myguest] is just the text variable I used to welcome users who are not logged in or anonymous users. I would not recommend creating such a user. If your site requires a user to login, then just drop that line. My site is left open so distant cousins can find it, which has worked very well these last couple of years once Google got it indexed.

Share this post


Link to post
Share on other sites
Russellgs

Thanks, Ken! Do I need to create a user 'myguest'?

Thanks,

Cyndi

Cyndi,

No you do not need to create a user 'myguest'. Anyone that visits your site that is not logged in will be by default a 'Guest'. He is creating a text file varable named $text[myguest] and assigning the name "Visitor" to that variable, so that whenever a person not logged in visits your site they will see the line "Welcome Visitor ..." instead of there user name.

Russ

Share this post


Link to post
Share on other sites
satyricon

Thanks, Adrian! Yes, I would like to see the code for this.

Hi Cyndi,

As you can see from the above there is more than one way to accomplish this. As I have had a bash at designing my own front page, the HTML/PHP I used looks like the following (obviously the colours, classes, alignments will probably not match your template as they are set up for the colours on my page):

<table width="900" class="standard" align="center" cellspacing="0" cellpadding="0" bgcolor="#E0E0FF" border="1">
  <tr>
    <td align="center">
      <?php
      if ($currentuser) {$welcome=$currentuserdesc;} else {$welcome=Visitor;} ?>
      <strong><br><font color=RED>Hello, <?php echo $welcome ?>, welcome to my Family History Website.</strong></font>
      <p>
      ... rest of table stuff goes here ...
    </td>
  </tr>
</table>

I don't profess to be an expert coder in either HTML or PHP so I'm sure the above is both clunky and inelegant in the eyes of some (or most). However, it does what it says on the tin.

I think the code is fairly self-evident, but please ask if there is anything needs clarifying.

Hope this helps,

Adrian

Share this post


Link to post
Share on other sites
gleehan

Folks following this thread and interested in personalizing their sites for logged in users may also want to see

Personalization post

Hi Cyndi,

As you can see from the above there is more than one way to accomplish this. As I have had a bash at designing my own front page, the HTML/PHP I used looks like the following (obviously the colours, classes, alignments will probably not match your template as they are set up for the colours on my page):

<table width="900" class="standard" align="center" cellspacing="0" cellpadding="0" bgcolor="#E0E0FF" border="1">
  <tr>
    <td align="center">
      <?php
      if ($currentuser) {$welcome=$currentuserdesc;} else {$welcome=Visitor;} ?>
      <strong><br><font color=RED>Hello, <?php echo $welcome ?>, welcome to my Family History Website.</strong></font>
      <p>
      ... rest of table stuff goes here ...
    </td>
  </tr>
</table>

I don't profess to be an expert coder in either HTML or PHP so I'm sure the above is both clunky and inelegant in the eyes of some (or most). However, it does what it says on the tin.

I think the code is fairly self-evident, but please ask if there is anything needs clarifying.

Hope this helps,

Adrian

Share this post


Link to post
Share on other sites
moreisbetter

Cyndi,

You will need to change topmenu.php and replace line 49

           <td> </td>
with the the following code, which is similar to that used in template 4 or 6
           <td> 
       <?php
    if( $currentuser ) {
        echo "<span class=\"whiteheader\">  $text[welcome], $currentuserdesc.</span>\n";
    }
    else {
        echo "<span class=\"whiteheader\">  $text[welcome], $text[myguest].</span>\n";
    } ?>
  </td>  
You will also need to add the following to your cust_text.php in each language folder
$text[myguest] = "Visitor";

Don't forget to document your changes in another file, so you can redo the changes if needed in the future.

I'm just now getting back to making this change, and although I thought I followed your instructions exactly, the only name that displays whether the user is logged in or not is 'Visitor'. Any ideas?

Thanks,

Cyndi

Share this post


Link to post
Share on other sites
Ken Roy

I'm just now getting back to making this change, and although I thought I followed your instructions exactly, the only name that displays whether the user is logged in or not is 'Visitor'. Any ideas?

Thanks,

Cyndi

Hi Cyndi,

Sorry, I may have left out the fact that you need to add the $currentuser and $currentuserdesc variables to the global statement, so the code in line 1 of template 5 would be

<?php global $text, $cms, $currentuser, $currentuserdesc; ?>

Share this post


Link to post
Share on other sites
moreisbetter

Hi Cyndi,

Sorry, I may have left out the fact that you need to add the $currentuser and $currentuserdesc variables to the global statement, so the code in line 1 of template 5 would be

<?php global $text, $cms, $currentuser, $currentuserdesc; ?>

Thanks, Ken - that did the trick!

Cyndi

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×