Add link rel="prev/next" to your blog

Published in Joomla

Google has been trying to improve the way it detects duplicate content on a website. URLs with parameters, such as the ones used for pagination, are tricky. You have the option to add a link tag to help Google identify this content. To read more about this check out the blog post in the Google webmaster blog.

To implement this in a Joomla template you can add the code in the overrides. For example you can open root/templates/your_template/html/com_content/blog.php. Inside it add this code:

// Add rel=prev/next
// http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
$doc =& JFactory::getDocument();
$pagdata = $this->pagination->getData();
if($pagdata->next->link){
 $doc->addHeadLink( $pagdata->next->link, 'next');
}
if($pagdata->previous->link){
 $doc->addHeadLink( $pagdata->previous->link, 'prev');
}

The variable $pagdata contains all the information about the pagination for the current page. We simply make a check for a next or previous page link. If there is one it means the page with other items exists so we can add the link tag. We do this with the addHeadLink function.

Read more...

Joomla 1.6 pagination override

Published in Joomla

Making an override for the pagination in Joomla 1.6 is almost as easy as working with other overrides. Sadly the new Beez template doesn't include an override for you to copy and use as a base so you have to create your own from the pagination file, which can be a little tricky at the beginning. To do this copy root/libraries/joomla/html/pagination.php to root/templates/your_template/html/pagination.php.

Read more...

Override print and email article icons

Published in Joomla

Overriding the icons used for the print and email icons in articles is very easy. In Joomla 1.6 you only need to create a new directory called system inside template_name/images/. Then place the blank index.html file and the printButton.png and emailButton.png images in there. Joomla will use these images instead of the default icons from root/media/system/images as long as the template is active.

Read more...

Access template parameters in error file

Published in Joomla

When you create a custom template you'll probably build in parameters to control the looks of the template. One small problem you may encounter is when creating the error.php and offline.php overrides you get an error when trying to access the parameters. If you use the normal $this->params->get('param'); you'll get the following error:

Fatal Error: Call to a member function get() on a non-object

To avoid this you should use the following code instead:

$templateParams = JFactory::getApplication()->getTemplate(true)->params;
$templateParams->get('param');

Read more...

Template language file

Published in Joomla

Sometimes when creating or editing a template you may have wondered how to include text strings without hard coding them. This is very simple when using the language system in Joomla. The first thing you need to do is create a file called xx-XX.tpl_{template-name}.ini, where xx-XX is the language code (for example en-GB for english or es-ES for spanish) and place it in root/language/xx-XX/. Inside it you can define the strings like this:

# comment
TPL_NAME_STRING = string

# example
TPL_HELIX_CHARACTERS_LEFT = Characters left

Read more...