How to manage random header image in joomla

In this post i would like to explain about how to manage random header image in joomla by the administrator. Just we have to create one folder for header images to store. And accessing those images through simple code and place it in the header part.

How to manage random header image in Joomla by Anil Kumar Panigrahi

How to manage random header image in Joomla by Anil Kumar Panigrahi

Follow below steps to activate it

  1. Create one page in admin section ( set_header_images.php )
  2. Create one folder at front-end application

Code for set_header_images.php

In my previous post i have explained about how to add or remove file fields using jquery, Try to use this code in your application and upload images to folder.

In the front-end application

/templates/{Your activated theme}/index.php

Get the images from the folder called header_images…

 <?php
    //echo $_SERVER['DOCUMENT_ROOT'];
    $folder = "".$_SERVER['DOCUMENT_ROOT']."/{Folder of application If it in localhost }/headers/";
    $extList = array();
        $extList['gif'] = 'image/gif';
        $extList['jpg'] = 'image/jpeg';
        $extList['jpeg'] = 'image/jpeg';
        $extList['png'] = 'image/png';
    $handle = opendir($folder);
    while ( false !== ( $file = readdir($handle) ) ) {
      $file_info = pathinfo($file);
      if (isset( $extList[ strtolower( $file_info['extension']          ) ] )) {
          $fileList[] = $file;
      }
    }
    closedir($handle);
   ?>

Style Sheet:

  <style type="text/css">
   #header{
    width:1007px;
    height:208px;
    background:url(<?php echo $this->baseurl ?>/headers/<?php echo $fileList[array_rand($fileList)];?>) no-repeat;/*position:fixed;*/
    position:relative;
    }
  </style>

Use this style in your header block like

 <div id="header">&nbsp;</div>

You can get random images each and every page of your joomla application.
 

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...

Leave a Reply

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