How to add image in joomla for each article sidebar

In this post i would like to explain about how to add image in joomla for each article sidebar. If we want to add some categories or articles images for sidebar of joomla website. Just cutomize the joomla code and implement it by simple code.

how to add image in joomla for each article sidebar | Anil Labs

how to add image in joomla for each article sidebar | Anil Labs

In the admin we have to place the below code in the file

\administrator\components\com_content\admin.content.html.php

Search for below code

echo $editor->display( 'text',  $row->text , '100%', '550', '75', '20' ) ;

After this we have add below code

<table>
    <tr valign="top">
            <td>Category Image</td>                            
            <td><input type="file" id="file-upload-entete" name="FileCategory" /></td>                             
            <td><img src='<?php echo JURI::base(); ?>../images/<?php echo $row->id; ?>/category.jpg' width=50 height=50 border=0></td>
            <td><input type="checkbox" name="delCategory"> </td>
    </tr>
</table>

We have upload the images at the file

\administrator\components\com_content\controller.php

Search for below code

$dispatcher->trigger('onAfterContentSave', array(&$row, $isNew));

After this line of code add in that page

if($_FILES['FileCategory']['tmp_name'] !=""){
         mkdir("../images/".$row->id); // Create folder for this article
         move_uploaded_file($_FILES['FileCategory']['tmp_name'],"../images/".$row->id."/category.jpg");
    }

In the front-end we have to get the image of particular article id and display it in the sidebar

Just open the file which is located at

templates\[YOUR TEMPLATE NAME]\html\com_content\article\default.php

Search for the below code

defined('_JEXEC') or die('Restricted access');

After this code add the below code:

$sEncartPath = $_SERVER["DOCUMENT_ROOT"] . "/images/" . $this->article->id . "/category.jpg";

In the sidebar we can write own syyles to display our category images… by below code

 <?php
 if (file_exists($sEncartPath))
 {
 ?>
  <img src="images/<?php echo $this->article->id;?>/category.jpg" width="256" height="220">
 <?php
 }
 ?>

Hope this will be useful.

Anil Kumar Panigrahi

With more than 10 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : [email protected]

You may also like...

3 Responses

  1. serge says:

    it is for 1.5 , isn’t it ?

  2. Simon says:

    Hi
    Where i can find this file in Joomla 2.5??
    Please let me know i realy want this to work ..

  3. bibin says:

    Nice tutorial,, must know guide for joomla developers..

Leave a Reply

Your email address will not be published. Required fields are marked *