random-image (template)

Displays a random image from image set of the file center

Docu: –
Forum: Display random image from filemanager

Autor: K.Heermann (flip-flop) http://planmatrix.de 2009/03/26
CMS version: >= V1.39
Version: V1.0
Update:

Tag:

Filename: random_image.tmpl
Folder: /template/inc_cntpart/images/

Condition: $phpwcms['allow_cntPHP_rt'] = 1;/config/phpwcms/conf.inc.php —-



Inspired by the contribution of breitsch here is an other general solution using the template for “image <div>” or “image special”.

It is very pretty and more flexible:

  • list of images from CP
  • width/heigth parameters from CP
  • lightbox (zoom only doesn´t run!!!).
  • alt/title from CP
  • build your own classes/IDs
  • fallback image (please insert your image into the snippet at the end)


random_image.tmpl

<!--IMAGES_HEADER_START//-->
 
<div class="images" id="images{ID}">
 
[PHP]
 
    $my_images = array();
    $my_counter = -1;
 
<!--IMAGES_HEADER_END//-->
 
 
<!--IMAGES_ENTRY_START//-->
 
    $my_counter++;
    $my_images[$my_counter][0] = '{IMAGE}';  // complete html string with image
    $my_images[$my_counter][1] = '{IMGID}';  // image-id
 
<!--IMAGES_ENTRY_END//-->
 
<!--IMAGES_ENTRY_SPACER_START//--><!--IMAGES_ENTRY_SPACER_END//-->
<!--IMAGES_ROW_SPACER_START//--><!--IMAGES_ROW_SPACER_END//-->
 
 
<!--IMAGES_FOOTER_START//-->
 
echo '<div class="imageEntry">'.LF;
 
if (!empty($my_images) ) {
    echo '<div id="img'.$my_images[$my_counter][1].'">'.LF;  // ID
 
//    srand(microtime()*1000000); // Only for php version < 4.2
    echo $my_images[rand(0,$my_counter)][0];  // iamge output
 
    echo '</div>'.LF;  // End ID
}
else
{ // ************* Please insert your fallback image *************
    echo '<img src="content/images/my_fallback_image.jpg" width="200" height="150" alt="My alt" title="My title" border="0" />';
}
echo '</div>'.LF;
 
unset ($my_images);
unset ($my_counter);
 
[/PHP]
 
</div>
<!--IMAGES_FOOTER_END//-->


More features

If you wan´t more features, please play around with the other parameter like {THUMB_HEIGHT} or {IMAGE_HASH} and so on.

<!--
      Thumbnail image: {THUMB_NAME}
        relative:      {THUMB_REL}
        absolute:      {THUMB_ABS}
        height/width:  {THUMB_HEIGHT}px/{THUMB_WIDTH}px
        image ID:      {IMAGE_ID}
        image Hash:    {IMAGE_HASH}
      
      If you are not sure wrap zoomed image:
      [ZOOM]
      Zoomed (big) image: {IMAGE_NAME}
        relative: {IMAGE_REL}
        absolute: {IMAGE_ABS}
        height/width: {IMAGE_HEIGHT}px/{IMAGE_WIDTH}px
      [/ZOOM]      
   //-->

Parameters hand over

from the range
<!--IMAGES_ENTRY_START//-->
 
$my_images[$my_counter][2] = '{THUMB_HEIGHT}'; // image-id
$my_images[$my_counter][3] = '{THUMB_WIDTH}'; // image-id
// and so on .......
 
<!--IMAGES_ENTRY_END//-->
into the range
<!--IMAGES_FOOTER_START//-->
 
echo 'Test thumb height'.$my_images[$my_counter][2].'<br />'.LF;
echo 'Test thumb width'.$my_images[$my_counter][3].'<br />'.LF;
 
<!--IMAGES_FOOTER_END//-->
english/phpwcms-system/article/contentparts/images-div/template-random-image.txt · Last modified: 2018/06/03 18:09 (external edit)
www.planmatrix.de www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0