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…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 <?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:

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

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

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


0 Comments

Leave a Reply

Avatar placeholder

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