Jump to content

[Solved] show slideshow only on home page


sixthmind

Recommended Posts

I have hardcoded jquery slideshow into header.tpl and now I am having some problems with displaying it where I want it to be displayed.

 

I put this code before the slider:

{if $page_name = 'index'}

 

and after slider

{/if}

 

The results of this are mixed. The slider is displayed on home page but it's also displayed on inner pages (categories pages and cms pages) only that is broken (no jquery called).

 

What code could I use to display slider only on home page? Your help would be really appreciated.

Link to comment
Share on other sites

  • 2 months later...

i have the inversed problem : i have s jquery image slider, it shows/appears only on FRONTPAGE and i want it to be shown on all pages (How hard Prestashop is ??) , here is a the code of install :

 

function install()

{

if (!parent::install() OR !$this->registerHook('home'))

return false;

return true;

}

 

what ever i write in place of this code it never works, why ??

help me plz, thx :) .

 

and here is all the whole code of jqueryslider.php :

<?php

/** Modulo JQuerySlider Galery **/

/** www.tiendasvirtuales.com.ve **/

 

class JQuerySlider extends Module

{

/** @var max image size */

protected $maxImageSize = 307200;

 

function __construct()

{

$this->name = 'jqueryslider';

$this->tab = 'Home';

$this->version = '1.2';

 

/* The parent construct is required for translations */

parent::__construct();

 

$this->page = basename(__FILE__, '.php');

$this->displayName = $this->l('JQuerySlider Galery');

$this->description = $this->l('Rotador de imagenes');

}

 

function install()

{

if (!parent::install() OR !$this->registerHook('home'))

return false;

return true;

}

 

 

 

 

 

function putContent($xml_data, $key, $field)

{

$field = htmlspecialchars($field);

if (!$field)

return 0;

return ("\n".' <'.$key.'>'.$field.'</'.$key.'>');

}

 

function getContent()

{

global $cookie;

/* Languages preliminaries */

$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));

$languages = Language::getLanguages();

$iso = Language::getIsoById($defaultLanguage);

$isoUser = Language::getIsoById(intval($cookie->id_lang));

 

 

/* display the module name */

$this->_html = '<h2>'.$this->displayName.' '.$this->version.'</h2>';

 

/* update the editorial xml */

if (isset($_POST['submitUpdate']))

{

// Generate new XML data

$newXml = '<?xml version=\'1.0\' encoding=\'utf-8\' ?>'."\n";

$newXml .= '<links>'."\n";

$i = 0;

foreach ($_POST['link'] as $link)

{

$newXml .= ' <link>';

foreach ($link AS $key => $field)

{

if ($line = $this->putContent($newXml, $key, $field))

$newXml .= $line;

}

 

/* upload the image */

if (isset($_FILES['link_'.$i.'_img']) AND isset($_FILES['link_'.$i.'_img']['tmp_name']) AND !empty($_FILES['link_'.$i.'_img']['tmp_name']))

{

Configuration::set('PS_IMAGE_GENERATION_METHOD', 1);

if ($error = checkImage($_FILES['link_'.$i.'_img'], $this->maxImageSize))

$this->_html .= $error;

elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['link_'.$i.'_img']['tmp_name'], $tmpName))

return false;

elseif (!imageResize($tmpName, dirname(__FILE__).'/'.$isoUser.$i.'.jpg'))

$this->_html .= $this->displayError($this->l('An error occurred during the image upload.'));

unlink($tmpName);

}

if ($line = $this->putContent($newXml, 'img', $isoUser.$i.'.jpg'))

$newXml .= $line;

$newXml .= "\n".' </link>'."\n";

$i++;

}

$newXml .= '</links>'."\n";

 

/* write it into the editorial xml file */

if ($fd = @fopen(dirname(__FILE__).'/'.$isoUser.'links.xml', 'w'))

{

if (!@fwrite($fd, $newXml))

$this->_html .= $this->displayError($this->l('Unable to write to the editor file.'));

if (!@fclose($fd))

$this->_html .= $this->displayError($this->l('Can\'t close the editor file.'));

}

else

$this->_html .= $this->displayError($this->l('Unable to update the editor file.<br />Please check the editor file\'s writing permissions.'));

}

 

/* display the editorial's form */

$this->_displayForm();

 

return $this->_html;

}

 

private function _displayForm()

{

global $cookie;

/* Languages preliminaries */

$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));

$languages = Language::getLanguages();

$iso = Language::getIsoById($defaultLanguage);

$isoUser = Language::getIsoById(intval($cookie->id_lang));

 

 

/* xml loading */

$xml = false;

if (file_exists(dirname(__FILE__).'/'.$isoUser.'links.xml'))

if (!$xml = @simplexml_load_file(dirname(__FILE__).'/'.$isoUser.'links.xml'))

$this->_html .= $this->displayError($this->l('Your links file is empty.'));

$this->_html .= '<br />

<form method="post" action="'.$_SERVER['REQUEST_URI'].'" enctype="multipart/form-data">

 

 

<fieldset style="width: 900px;">

<legend>'.$this->l('Ayuda').'</legend>

<text>'.$this->l('<b>Configuración:</b> Ud puede ingresar desde aquí las imagenes a presentar en su "slider" con el respectivo link de cada una de ellas.').'<br>'.

$this->l('Si desea que esta sección contenga mas imagenes entonces edite e inserte manualmente dentro del archivo "links.xml" tantos campos "link" como necesite.').'<br>'.

$this->l('Por defecto sólo serán mostradas hasta 4 imagenes, pero ello es ampliable.').'<br>'.

$this->l('<b>Importante:</b> Todas las imagenes deberán tener el mismo tamaño en ancho y alto expresado en pixeles.').'<br>'.

$this->l('Para cambiar el tamaño del contenedor de las imagenes deberá editar el archivo <b>/prestashop/modules/jqueryslider/css/jqueryslider.css</b> y modificar los valores: width,height.').'<br>'.

$this->l('Velocidad y otros parámetros los pueden editar desde el archivo: <b>/prestashop/modules/jqueryslider/js/easySlider1.5.js</b>').'<br><br>'.

$this->l('Estos cambios sólo serán realizados la primera vez, despues podrá realizar cambios de imagenes sin necesidad de editar nuevamente los valores de arriba mencionados.').'</text>

</fieldset>

 

 

<fieldset style="width: 900px;">

 

 

 

<legend><img src="'.$this->_path.'logo.gif" alt="" title="" /> '.$this->displayName.'</legend>';

$i = 0;

foreach ($xml->link as $link)

{

$divLangName = 'title'.$i.'¤cpara'.$i;

$this->_html .= '<h4>'.$this->l('Slider #').$i.'</h4>';

$this->_html .= '<div class="clear"></div>';

$this->_html .= '

 

<fieldset style="width:870px">

<h5><label>'.$this->l('Imagen (Vista al 50%)').'</label></h5>

<div class="margin-form">

<img src="'.$this->_path.$isoUser.$i.'.jpg" alt="" title="" style="width:50%; height:50%;" /><br />

<input type="file" name="link_'.$i.'_img" />

</div>

<h5><label>'.$this->l('Enlace').'</label></h5>

<div class="margin-form">

<input type="text" name="link['.$i.']" size="64" value="'.($xml ? stripslashes(htmlspecialchars($xml->link[$i]->url)) : '').'" />

</div>

</fieldset>';

 

$i++;

}

 

$this->_html .= '

<div class="margin-form clear">

<div class="clear pspace"></div>

<div class="margin-form">

<input type="submit" name="submitUpdate" value="'.$this->l('Guardar').'" class="button" />

</div>

</div>

 

</fieldset>

</form>';

}

 

function hookHome($params)

{

global $cookie;

/* Languages preliminaries */

$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));

$languages = Language::getLanguages();

$iso = Language::getIsoById($defaultLanguage);

$isoUser = Language::getIsoById(intval($cookie->id_lang));

 

if (file_exists(dirname(__FILE__).'/'.$isoUser.'links.xml'))

if ($xml = simplexml_load_file(dirname(__FILE__).'/'.$isoUser.'links.xml'))

{

global $cookie, $smarty;

$smarty->assign(array(

'xml' => $xml,

'this_path' => $this->_path

));

return $this->display(__FILE__, 'jqueryslider.tpl');

}

return false;

}

}

 

?>

 

////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////

 

here the code of jqueryslider.tpl :

{literal}

<!-- MODULE JQuerySlider Galery -->

<!-- www.tiendasvirtuales.com.ve -->

 

<script type="text/javascript" src="{/literal}{$this_path}{literal}js/easySlider1.5.js"></script>

<link rel="stylesheet" type="text/css" href="{/literal}{$this_path}{literal}css/jqueryslider.css" />

 

<div id="container">

<div id="slider">

<ul>

{/literal}

{foreach from=$xml->link item=home_link name=links}

{literal}

<li><a href='{/literal}{$home_link->url}{literal}'><img src='{/literal}{$this_path}{$home_link->img}{literal}'alt="" /></a></li>

{/literal}

{/foreach}

{literal}

</ul>

</div>

</div>

 

<script type='text/javascript' id='slider'>

$(function() {

$("#slider").easySlider()

});

</script>

<!-- /MODULE JQuerySlider Galery -->

{/literal}

Link to comment
Share on other sites

thank you, i solved my problem before you answer me , but thank you again, i created as you told me a new hook and installed it there, but how had was that to do, first hack/change the code of the module, second insert the hook name in the database ,third insert the hook command in "FrontController.php" that was in /controllers/ folder... :blink::wacko: .

here is the final site link : http://ares-reseau.net/boutique/shope/fr/ .

thank u again, happy to meet you :)

Link to comment
Share on other sites

  • 1 year later...

Hello,

Thank you for your posts, very useful!

 

I have a similar problem now:

 

I would like to show a module only on a category page: do you know I can I do?

 

Thank you!

 

go to modules > positions click on edit button near this module (in each of list)

then define exceptions, select all pages instead "category"

Link to comment
Share on other sites

  • 4 weeks later...

Easier:

 

modules/homeslider/homeslider.tpl

 

include:

{if $page_name == 'index'}

and:

{/if}

result:

{if $page_name == 'index'}

    {if isset($homeslider_slides)}
    <ul id="homeslider">
    {foreach from=$homeslider_slides item=slide}
        {if $slide.active}
            <li>
                <a href="{$slide.url|escape:'htmlall':'UTF-8'}" title="{$slide.description|escape:'htmlall':'UTF-8'}">
                <img src="{$smarty.const._MODULE_DIR_}homeslider/images/{$slide.image|escape:'htmlall':'UTF-8'}" alt="{$slide.legend|escape:'htmlall':'UTF-8'}" height="{$homeslider.height|intval}" width="{$homeslider.width|intval}" />
                </a>
            </li>
        {/if}
    {/foreach}
    </ul>
    {/if}


{/if}

Greetings from Spain!

  • Like 2
Link to comment
Share on other sites

Thank you!

 

go to modules > positions click on edit button near this module (in each of list)

then define exceptions, select all pages instead "category"

 

Vekia: I do not have exactly that problem...

I mean: I would like to show a module only on a particular category page, not on all the categories pages. 

 

Can you help?

 

Tanks!

Link to comment
Share on other sites

you can do it with if conditions but in this case you will need to modify module files.

 

{if isset($smarty.get.id_cat)}

  {if $smarty.get.id_cat==6}

    SLIDER CONTENTS HERE

  {/if}

{/if}

 

this code will show slider only on category id = 6

Link to comment
Share on other sites

  • 3 months later...

you can do it with if conditions but in this case you will need to modify module files.

 

{if isset($smarty.get.id_cat)}

  {if $smarty.get.id_cat==6}

    SLIDER CONTENTS HERE

  {/if}

{/if}

 

this code will show slider only on category id = 6

Hi all,

 

I want to achieve a similar thing with the blockcategories module - I want the module to only display on certain category pages (I'm using layered navigation for other categories).

 

I tried using the above code on blockcategories.tpl but it doesn't work, the module doesn't appear on any categories.

 

Any ideas?

 

PS 1.5.6.2

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...