Joomla Hacks & Hints

Joomla is annoying from time to time when you think something should be simple but it just complicates matters here are some hints and little hacks that can help you get the most out of Joomla.

Creating a logout link within a menu

Joomla by default won’t allow you to add a direct link to logout – instead the link takes you to the login page with a button to allow your user to logout resulting in a long winded process. Did a little searching and came across a solution where by you create a link to an external url in your menu to the following;

index.php?option=com_user&task=logout&return=aW5kZXgucGhw

The return value is a Base64 encoded string to index.php you can change this to redirect the user to any location once they click the link and logout,just copy the return location into the following site

Example
index.php?option=com_content&view=article&id=1&Itemid=2
Result
aW5kZXgucGhwP29wdGlvbj1jb21fY29udGVudCZ2aWV3PWFydGljbGUmaWQ9MSZJdGVtaWQ9Mg

Check user logged in within template

Want to include something in your template that only users that have logged then you can use the following code;

<?php
$checkuser = JFactory::getUser(); //include this in your template code near the top
if ($checkuser->get(‘gid’)>0){
//show whatever you want to a logged in user
}
else {
//the user isn’t logged in so show them something else
}
?>

Change Page Titles to include website name instead of item title

By default Joomla will set your page titles to the name of the content item/component so if you have a piece of news “We open our store” then this would be your page title.

I don’t like this I would much prefer the title to be the site name followed by the name of the item.

You can set your page titles up however you want with the following code

<php
$mydoc =& JFactory::getDocument();
$mytitle = $mydoc->getTitle(); //get the title specific to this content item/component
$conf =& JFactory::getConfig();
$sitename = $conf->getValue(‘config.sitename’); //get the site name from the config file

$mydoc->setTitle($sitename.’ – ‘.$mytitle); //overide the title of the page
?>

Post by: Richard

Tags: , , , ,

2 Responses to “Joomla Hacks & Hints”

  1. JamesD says:

    Thanks for the useful info. It’s so interesting

  2. Pete says:

    Reckon we should draw up a list of these sorts of things Rich. Useful stuff that you can’t find on the forums without digging

Leave a Reply