Automatically create Section images from 1st product within that section that has a jpg image.
If a section image is defined it will be used.
If no section image is defined then the products within that section are searched for one with an image.
If no product image exists then the default section image is used.
INSTALLATION
In your Site folder, create a sub-folder called "Thumbnails".
Go to Design / Library / Variables / Section.
Right-click Section and choose New Variable.
Set the new variable as follows:
Go to Design / Library / Layouts / Section Links.
Right-click "CSS Section Link layout" and select Copy.
Rename that copy layout to be "CSS Section with Product Image Thumbnail".
Open layout "CSS Section with Product Image Thumbnail".
Replace the entire contents of that layout with the following:
That's installation done.
OPERATION
To select this layout, go to Settings / Site Options / Layout / Section
and set Section Link Layout to "CSS Section with Product Image Thumbnail".
To alter the image width, go to Settings / Site Options / Layout / Section
and set Section Image Scaled Width as required.
If a section image is defined it will be used.
If no section image is defined then the products within that section are searched for one with an image.
If no product image exists then the default section image is used.
INSTALLATION
In your Site folder, create a sub-folder called "Thumbnails".
Go to Design / Library / Variables / Section.
Right-click Section and choose New Variable.
Set the new variable as follows:
Code:
Name: SectionImageScaledWidth Description: Automatically resized section image from product image. Prompt: Section Image Scaled Width Group: Section Place Of Setting Site Allow <Use Parent>... Checked Tab Name / Panel Name: Layout Type: Number Allow Empty Value: Unchecked Whole Numbers Only: Checked Searchable: Unchecked Modifiable In Dup: Unchecked Upload: Unchecked Initial Value Use Parent Top Level Value 75
Go to Design / Library / Layouts / Section Links.
Right-click "CSS Section Link layout" and select Copy.
Rename that copy layout to be "CSS Section with Product Image Thumbnail".
Open layout "CSS Section with Product Image Thumbnail".
Replace the entire contents of that layout with the following:
Code:
<div class="product_list"> <div class="image_product"> <a href="<actinic:block if="%3cactinic%3avariable%20name%3d%22IsLoginPageSuppressed%22%20%2f%3e%20AND%0d%3cactinic%3avariable%20name%3d%22UnregCustomersAreNotAllowed%22%20%2f%3e" ><actinic:variable name="SectionPageName" /></actinic:block><actinic:block if="%28%3cactinic%3avariable%20name%3d%22IsLoginPageSuppressed%22%20%2f%3e%20%3d%3d%20false%29%20OR%0d%28%3cactinic%3avariable%20name%3d%22UnregCustomersAreNotAllowed%22%20%2f%3e%20%3d%3d%20false%29" ><actinic:variable name="SectionURL" /></actinic:block>" target="_self"> <actinic:block php="true" > // V1.03 $noimageyet = true; if ( ( basename('<actinic:variable encoding="perl" name="SectionImageFileName" selectable="false" />') == basename('<actinic:variable name="DefaultSectionImage" encoding="perl" selectable="false" />') ) || ( basename('<actinic:variable encoding="perl" name="SectionImageFileName" selectable="false" />') == basename('<actinic:variable name="MainSection::SectionImageFileName" encoding="perl" selectable="false" />') ) ) { <actinic:block type="ProductList" > $sOriginalImageName = '<actinic:variable encoding="perl" name="ProductImageFileName" selectable="false" />'; if ( $noimageyet && ($sOriginalImageName != "") && strpos(strtolower($sOriginalImageName), '.jpg') ) { $sOriginalImageName = str_replace('\\','/', $sOriginalImageName); $nScaledWidth = <actinic:variable name="SectionImageScaledWidth" encoding="perl" selectable="false" />; $sThumbImageName = 'Thumbnails/s_' . basename($sOriginalImageName); $image = @imagecreatefromjpeg($sOriginalImageName); /* Attempt to open */ if (!$image) { /* See if it failed */ echo "<br><font color=red>Thumbnail creation error opening: $sOriginalImageName </font>"; } else { // Get new dimensions $width = imagesx($image); $height = imagesy($image); $t_width = $nScaledWidth; $t_height = round($height * ($t_width / $width)); // Resample $thumbimage = imagecreatetruecolor($t_width, $t_height); imagecopyresampled($thumbimage, $image, 0, 0, 0, 0, $t_width, $t_height, $width, $height); if ( ! imagejpeg($thumbimage, $sThumbImageName) ) { echo "<font color=red>Thumbnail image creation failed: $sThumbImageName </font><br>"; } else { echo "<img src=\"$sThumbImageName\" width=\"$t_width\" height=\"$t_height\" border=\"0\""; echo " alt=\"<actinic:variable name="SectionName" encoding="strip"/>\" />"; } } $noimageyet = false; } </actinic:block> } if ( $noimageyet ) { echo "<img src=\"<actinic:variable encoding="perl" name="SectionImageFileName" selectable="false" />\""; echo " width=\"<actinic:variable name="SectionImageWidth" />\""; echo " height=\"<actinic:variable name="SectionImageHeight" />\" border=\"0\""; echo " alt=\"<actinic:variable name="SectionName" encoding="strip"/>\" />"; } </actinic:block> </a> </div> <div> <h3 class="product"><a href="<actinic:block if="%3cactinic%3avariable%20name%3d%22IsLoginPageSuppressed%22%20%2f%3e%20AND%0d%3cactinic%3avariable%20name%3d%22UnregCustomersAreNotAllowed%22%20%2f%3e" ><actinic:variable name="SectionPageName" /></actinic:block><actinic:block if="%28%3cactinic%3avariable%20name%3d%22IsLoginPageSuppressed%22%20%2f%3e%20%3d%3d%20false%29%20OR%0d%28%3cactinic%3avariable%20name%3d%22UnregCustomersAreNotAllowed%22%20%2f%3e%20%3d%3d%20false%29" ><actinic:variable name="SectionURL" /></actinic:block>" target="_self"><actinic:variable name='SectionName'/></a></h3> </div> <p><actinic:variable name='SectionDescription'/></p> </div>
OPERATION
To select this layout, go to Settings / Site Options / Layout / Section
and set Section Link Layout to "CSS Section with Product Image Thumbnail".
To alter the image width, go to Settings / Site Options / Layout / Section
and set Section Image Scaled Width as required.
Comment