test
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • kashxo Friend
    #130306

    Here, I will show you how to customize JA Script to get what you want. This version if for Joomla! 1.5.x
    ————
    In this tutorials, we will go through steps to make background of JA NewsFlash in JA Kulanite fixed for each menu item (instead of random image as now).

    STEP 1: Open file ja_templatetools_1.5.php in folder templates/ja_kulanite, then add this function to the bottom of the file:
    <blockquote>
    function showHeaderImage () {
    $Itemid = JRequest::getInt( ‘Itemid’);

    //.. DEFINE YOUR ARRAY OF IMAGES HERE …….
    $images_array = array(“1” => “templates/ja_kulanite/images/header/hd-1.jpg”,
    “53” => “templates/ja_kulanite/images/header/hd-2.jpg”,
    “27” => “templates/ja_kulanite/images/header/hd-3.jpg”,
    “default” => “images/stories/clock.jpg” # this image will be shown if Itemid not in the list
    );
    //…………………………………….

    //.. Now checking ………………………
    $image = “”;
    $found = false;
    foreach ($images_array as $key => $value) {
    if (strval($key) == strval($Itemid)) $found = true;
    }

    if ($found) {
    $image = $images_array[“$Itemid”]; # Return the image if found
    } else {
    $image = $images_array[“default”]; # else, we return default image
    }

    return $image;
    }
    </blockquote>

    As you can see in the code, you can define the image for each menu id here. To add more, just simply add the following to the array: “itemid” => “path/to/the/image”. The default value should be define because it will be needed when Itemid is not in the list. You can define the image from everywhere, start from your root folder.

    STEP 2: Now, open the index.php file in folder templates/ja_kulanite. At the line 125th, you will found this code:
    <blockquote><div id=”ja-topsl” style=”background:url(<?php echo $tmpTools->templateurl().”/images/header/”.$tmpTools->getRandomImage(dirname(__FILE__).DS.”images”.DS.”header”);?>)”></blockquote>

    Replace it with this code:
    <blockquote><div id=”ja-topsl” style=”background:url(<?php echo JURI::base().’/’.$tmpTools->showHeaderImage();?>)”></blockquote>

    Oh yeah, you are right. That’s the function we’ve made in JA Template Tools at step1. And what we should do now is just refresh the site to see our change.
    Goodluck. (If you got difficult while adding this code, you know that you can always PM me)

    brucetaylor Friend
    #265685

    Hi kashxo,

    I have copied this line for line and I get the follwoing error –

    <div id=”ja-topsl” style=”background:url (
    Fatal error: Call to undefined method JA_Tools::showHeaderImage() in /home/divemidl/public_html/opsun/templates/ja_kulanite/index.php on line 125

    I replaced
    <?php if ($this->countModules(‘user5’)) { ?>
    <!– BEGIN: TOPSPOTLIGHT –>
    <div id=”ja-topsl” style=”background:url(<?php echo $tmpTools->templateurl().”/images/header/”.$tmpTools->getRandomImage(dirname(__FILE__).DS.”images”.DS.”header”);?>)”>
    <jdoc:include type=”modules” name=”user5″ style=”xhtml” />
    </div>
    <!– END: TOPSPOTLIGHT –>
    <?php } ?>

    with –

    <?php if ($this->countModules(‘user5’)) { ?>
    <!– BEGIN: TOPSPOTLIGHT –>
    <div id=”ja-topsl” style=”background:url(<?php echo JURI::base().’/’.$tmpTools->showHeaderImage();?>)”>
    <jdoc:include type=”modules” name=”user5″ style=”xhtml” />
    </div>
    <!– END: TOPSPOTLIGHT –>
    <?php } ?>

    In the index.php and added the ja_templatetools_1.5.php lines. Before the last ?>

    This is on a test site, so can’t provide a URL.

    Any idea’s?

    Thanks

    anatta Friend
    #266230

    Thanks for this incredibly useful post. I have modified your function slightly so that I can specify an image if I want, or default to a random set of images. The function uses static paths, so please note that I am using the ja_iolite template and that my static images are in a folder header2 – so please make sure that you adjust the paths to fit your environment.

    Also, for those less experienced with PHP, be sure to post this function before the final ‘}’ so that it is included in the JA_Tools class, otherwise you will find that it does not work.

    Hope this helps someone ;).

    <blockquote>function showHeaderImage () {
    $Itemid = JRequest::getInt( ‘Itemid’);

    //.. DEFINE YOUR ARRAY OF IMAGES HERE …….
    $images_array = array(“70” => “/templates/ja_iolite/images/header2/hd-1.jpg”,
    “71” => “/templates/ja_iolite/images/header2/hd-2.jpg”,
    “default” => “/templates/ja_iolite/images/header/”.$this->getRandomImage(“templates/ja_iolite/images/header”) # random image function will be called if Itemid not in the list
    );
    //…………………………………….

    //.. Now checking ………………………
    $image = “”;
    $found = false;
    foreach ($images_array as $key => $value) {
    if (strval($key) == strval($Itemid)) $found = true;
    }

    if ($found) {
    $image = $images_array[“$Itemid”]; # Return the image if found
    } else {
    $image = $images_array[“default”]; # else, we return random image
    }

    return $image;
    }
    </blockquote>

    You will also need to adjust index.php to call this function as explained above.

    anatta Friend
    #266233

    Bruce,

    This error occurs because the function is not part of the JA_Tools class. The function must be posted before the last } to include it in the JA_Tools class.

    To correct your code remove the } on the line immediately preceding:

    function showHeaderImage () {

    and add a } above the last line

    ?>

    The tail of your ja_templatetools_1.5.php should now look like:

    <blockquote>……
    if ($found) {
    $image = $images_array[“$Itemid”]; # Return the image if found
    } else {
    $image = $images_array[“default”]; # else, we return random image
    }

    return $image;
    }

    }

    ?></blockquote>

    scofz Friend
    #277965

    So how do I apply this logic to the ja-header function. What I would like to do is show a specific image on the home page, but randomise the header image for all other pages in the site

    Here is the code “as is” in the index.php of the JA_Purity template :-

    <div id=”ja-headerwrap”>

    <div id=”ja-header” class=”clearfix” style=”background: url(<?php echo $tmpTools->templateurl(); ?>/images/header/<?php echo $tmpTools->getRandomImage(dirname(__FILE__).DS.’images/header’); ?>) no-repeat top <?php if($this->direction == ‘rtl’) echo ‘left’; else echo ‘right’;?>;”>

Viewing 5 posts - 1 through 5 (of 5 total)

This topic contains 5 replies, has 4 voices, and was last updated by  scofz 16 years, 1 month ago.

We moved to new unified forum. Please post all new support queries in our New Forum