Welcome Joomler!

On this page, you will find some useful tips and snippets for overriding your Joomla layouts. I collect them since years and I've decided to share these helpful piece of code with Jommla overrides friends. Don't hesistate to bookmark this page with CTRL+D .

Caution!

Before creating and applying an override on your Joomla site, you must backup your site. Do it again. And again.. In any case, I will not be responsible of an error on your website.
Thanks in advance to give me feedback about these overrides. Feel free to share yours and to improve mine.

Some useful videos about Joomla overrides

Some useful php codes for your overrides

  1. Print_r

    print_r — Prints human-readable information about a variable

    <?php
    /**
     * @package     Joomla.Site
     * @subpackage  mod_articles_archive
     *
     * @copyright   Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
     * @license     GNU General Public License version 2 or later; see LICENSE.txt
     */
    
    defined('_JEXEC') or die;
    ?>
    <?php if (!empty($list)) : ?>
      
    	<ul class="archive-module<?php echo $moduleclass_sfx; ?> mod-list">
      
    	<?php foreach ($list as $item) : ?>
          
        <div>
          <pre>
            <?php print_r($item);?>
          </pre>
          </div>
                  
    	<?php endforeach; ?>
          
    </ul>
    <?php endif; ?>
    
  2. Display the intro image of an article

    <?php
    	$article_images  = json_decode($item->images);
    	$article_image   = '';
    	$article_image_alt   = '';
    	if(isset($article_images->image_intro) && !empty($article_images->image_intro)) {
    		$article_image  = $article_images->image_intro;
    		$article_image_alt  = $article_images->image_intro_alt;
    	}?>  					
    		
    	<a href="/<?php echo $item->link; ?>">
    		<img class="" src="/<?php echo $article_image; ?>" alt="<?php echo $article_image_alt; ?>" >
    	</a>
  3. Display custom fields in an override 

    <?php $customFields = FieldsHelper::getFields('com_content.article', $this->item, true);
    		foreach ($customFields as $customField){
    		$customFields[$customField->name] = $customField;
    	}?> 
    	
    	
    <p><?php echo $customFields['name-of-the-custom-field']->value; ?></p>
  4. Display the number of articles in a category

    <?php 
    $model = JModelLegacy::getInstance('Articles', 'ContentModel', array( 'ignore_request' => true )); 
    $params = JFactory::getApplication()->getParams();
    $model->setState('params', $params);
    $model->setState('filter.category_id', xxxx); // xxxx category ID 
    $num_articles = $model->getTotal();
    ?>
    
    <p><?php echo $num_articles; ?></p>
  5. Truncate the introtext

    <?php echo JHTML::_('string.truncate', $item->introtext, 100, false, false) ; ?>
    
  6. Display the name of the site

    <?php
    $config = JFactory::getConfig();
    echo 'Site name is ' . $config->get( 'sitename' ); 
    ?>
  7. Display images from weblink component

    <?php $images = json_decode($item->images); ?>
    <?php  if (isset($images->image_first) and !empty($images->image_first)) : ?>
    <div class="img-intro pull-<?php echo htmlspecialchars($images->float_first); ?>"> 
    	<img src="/<?php echo $images->image_first; ?>" />
    </div>
    <?php endif; ?>
                      
    <?php  if (isset($images->image_second) and !empty($images->image_second)) : ?>
    <div class="img-thumbnail img-intro pull-<?php echo htmlspecialchars($images->float_second); ?>"> 
    	<img src="/<?php echo htmlspecialchars($images->image_second); ?>" />
    </div>
    <?php endif; ?>
  8. Display the number of articles

    <?php if ($params->get('numitems')) : ?>
    (<?php echo $item->numitems; ?> articles)
    <?php endif; ?>
    
  9. Display the category name

    <?php echo $item->displayCategoryTitle; ?>
    
  10. Display the content of URL A field

    <?php echo $item->urls->get('urlatext'); ?>
    
  11. Display the image of the category

    <img src="<?php echo $item->getParams()->get('image') ?>" class=""/>

web-eau.net

France - 29800 Landerneau

+33 674 502 799

daniel@web-eau.net

Quick links