A bunch of tips and snippets before starting to override

Caution!

Before creating and applying any override, you must know what you are doing. In any case, I will not be responsible of an error on your website.


Backup your site before any modification. Do it again. And again.


Thanks in advance to give me feedback about these overrides and feel free to share yours and 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', $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; ?>
A PROPOS DE L'AUTEUR :
Webmaster freelance passionné par Joomla depuis 2007, Daniel défend la veuve et l'orphelin du web en créant des sites respectueux du W3C. Fort d'une expérience de plusieurs années, il partage ses connaissances dans un état d'esprit open source.
Daniel est également très impliqué dans la communauté Joomla depuis 2014 en étant membre actif de plusieurs projets, conférencier et fondateur du JUG Breizh.