Collapse Joomla module for logged in users.
Problem: When logged in the User Menu was causing two modules to break out of the site frame. The client had to have scroll-bars against everyone’s wishes…
Solution: Using a few built in Joomla tools
- $user =& JFactory::getUser(); – simple means of organizing objects by user
- if ($user->get(‘guest’) == 1) – if visitor is guest (true)
- {$showcontactandsocial = $this->countModules(‘contact or social’); } – sets the variable and defines the module to be displayed based on user session
Basically if the user is a guest it means they are not logged in. This code tells Joomla to display the Contact and Social modules if the user is NOT logged in. If they see the modules then they are a guest visitor and have not logged in. This code goes in just above </head>
<?php
$user =& JFactory::getUser();
if ($user->get('guest') == 1) {
$showcontactandsocial = $this->countModules('contact or social'); }
?>
Here’s the call to our function in the Body:
<?php if ($showcontactandsocial) : ?>
<div>
<span>
<jdoc:include type="modules" name="contact" />
<jdoc:include type="modules" name="social" />
</span>
</div>
<?php endif; ?>
This worked great in joomla 1.5.20+
***UPDATED***
if($user->get('guest') == 1 || $user->usertype == 'Registered')
This allows Guest and Registered users to see the module but hides from all other groups




