Displaying arbitrary product image in Shop-Script 5 slider

In basic desi themes CUSTOM, Sidebar, and Clear, the slider in the home page by default displays the main (first) image of each product added to the bestsellers set. If you would like to change this default behavior and display a different (e.g., second or last) product image in the slider, you need to modify the original design theme as described in this article.

Displaying product image with specified index number

The HTML code for displaying product image in the slider is generated by means of the following function in the home.html template:

{$wa->shop->productImgHtml($p, '970', ['itemprop' => 'image', 'alt' => $p.name, 'default' => "`$wa_theme_url`img/dummy200.png"])}

If you need to have the second product image displayed instead of the first one, add the following extra code before that line:

{$_product = $wa->shop->product($p.id)}
{$product_image_ids = array_keys($_product.images)}
{$slider_image = $_product.images[$product_image_ids[1]]}
{$p.image_id = $slider_image.id}
{$p.ext = $slider_image.ext}

In this code, the 1 number indicates that the second product image should be displayed (numeration begins with zero). Hence, to have the 3rd image displayed in the slider, specify 2 instead of 1 in this example.

Displaying last product image

To have the last product image displayed in the slider regardless of the total number of images uploaded for each specific product, add the following code instead of that suggested in the previous example:

{$_product = $wa->shop->product($p.id)}
{$slider_image = end($_product.images)}
{$p.image_id = $slider_image.id}
{$p.ext = $slider_image.ext}

4 comments

  • 0
    Mohamed Ebrahim Mohamed Mohamed Ebrahim Mohamed January 16, 2014 06:50 #
    It is really a great tip but I Didn't find this line in Home.html in sidebar theme.
    I need this feature to use the second image.

    Please, help
    best regards
    • 0
      Mike Mike January 16, 2014 09:00 #
      This is probably because there is no slider in the Sidebar theme by default... Have you embedded it in your store's design template?
    • 0
      Mike Mike January 20, 2014 05:33 #
      It is there:
      {$wa->shop->productImgHtml($p, '400', ['itemprop' => 'image', 'alt' => $p.name, 'default' => "`$wa_theme_url`img/dummy200.png"])}
    • 0
      Mohamed Ebrahim Mohamed Mohamed Ebrahim Mohamed January 17, 2014 14:27 #
      there is slider by default
      http://www.swansonarabia.com/
      I didn't embed it

      Posting new comments is disabled for this topic.


      Раздел помощи работает на основе приложения «Хаб»