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

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

After this we have add below code

1
2
3
4
5
6
7
8
<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

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

After this line of code add in that page

1
2
3
4
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

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

After this code add the below code:

1
$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

1
2
3
4
5
6
7
8
 <?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.


3 Comments

serge · December 21, 2011 at 3:35 pm

it is for 1.5 , isn’t it ?

Simon · February 17, 2012 at 10:25 pm

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

bibin · March 18, 2013 at 3:52 pm

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

Leave a Reply

Avatar placeholder

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