Compassdesigns.net

Teaching - Web - Sailing

  • Home
  • Services

Show Different Content to Different Joomla Users

July 22, 2010 By barrie@compassdesigns.net Leave a Comment

First we need to make available information (aka accessing the user object) about the user, such as their name, or in this case, their user level.

To do this, we insert the following in the head of our template:

$user =& JFactory::getUser();

We can now echo all sorts of information about the user in the template, for example:

<p>Hi <?php echo $user->name ?>, you haven't logged in since 
<?php echo $user->lastvisitDate ?>.</p>

Remember, this has to be in the template index.php, you can’t echo this in an article or module as it needs to be processed at the template level.

Showing Different Content to Different Users

So now we use some CSS…

In our head we put:

<?php
if( !$user->guest ): ?>
<style type="text/css">
.logguest {display:none;}.logmember {}
</style>


<style type="text/css">
.logguest {}.logmember {display:none;}
</style>
<?php endif; ?>

Now, anything I want only guests to see, I surround with a class of logguest, anything I want only a logged in user to see I put a class of logmember. More importantly, because its now CSS, I can put it in a module or article!

For example:

<p class="logguest">
Dude, register already!
</p>
<p class="logmember">
Hi <?php echo $user->name ?>, you haven't logged in since
<?php echo $user->lastvisitDate ?>.
</p>

One thing to bear in mind, the content is still there, but its just not being shown via CSS, so Google will still see it (for example). Its a crude, but simple technique.

Other Content Hiding Options

If you need more control over what content is shown to what users, check out David Towers excellent review of JoomiHide, Ninja Access – JACL and RokAccess

Other User Object Variables

The full list can be found on the Joomla wiki:

  • id – The unique, numerical user id. Use this when referencing the user record in other database tables.
  • name – The name of the user. (e.g. Vint Cerf)
  • username – The login/screen name of the user. (e.g. shmuffin1979)
  • email – The email address of the user. (e.g. crashoverride@hackers.com)
  • password – The encrypted version of the user’s password
  • password_clear – Set to the user’s password only when it is being changed. Otherwise, remains blank.
  • usertype – The role of the user within Joomla!. (Super Administrator, Editor, etc…)
  • gid – Set to the user’s group id, which corresponds to the usertype.
  • block – Set to ‘1’ when the user is set to ‘blocked’ in Joomla!.
  • registerDate – Set to the date when the user was first registered.
  • lastvisitDate – Set to the date the user last visited the site.
  • guest – If the user is not logged in, this variable will be set to ‘1’. The other variables will be unset or default values.

This article has an SEO score of 100% and content, joomla, users, and show are emphasized within the content and are considered Primary Keywords.
Find out more about Scribe for Joomla

Filed Under: Uncategorized

The Skinny

I am an entrepreneur, web consultant, author and educator.

I have been involved in starting a K-12 School District, a Private High School, and three web tech companies. I also wrote one of the original and best selling books on Joomla.

And I like sailing with kids.

Recent Posts

  • Teenager Invents New Type of Hunting Camo Suit
  • A Parent’s Guide to Proficiency Based Learning
  • Proficiency/Competency Based Learning in NGSS Classrooms
  • Hunting Camouflage Website Launched
  • Get More Email Newsletter Signups With These Easy Tips
  • Proficiency Based Learning Resources
  • Social Media Redux
  • How to turn off WordPress Comments if you use Disqus
  • The API was Yesterday. The Tomorrow is iPaaS
  • Left Hook Digital Named Zapier’s First Integration Developer Partner

Top Posts

  • What Exactly is Standards-Based Teaching and Learning
  • USCG vs SOLAS Flares for Offshore Sailing

Blogroll

See3D Camo

Blaze Orange Camo

Vermont CPR

Copyright © 2023 Compass Designs ยท Musings on Education, Life, Joomla and the Web by Barrie North