Composr CMS Random Image Mini Block
Posted: Sat Feb 16, 2019 10:58 am
Hello,
Wanted to share this and invite people to make it better… You can change this for your own use in yoru site to show random pictures, etc.
I own a bookshop and want to display books on my website, a random book cover throughout the site that points back to the gallery that has more information for the potential customer.
see example usage:
https://nandalow.com/index.php?page=wik ... owse&id=41
Notice the upper left nandalow bookshop box is displaying a book cover. Now scroll down a bit and on the lower left & right it will display a random book or comic cover. In the center of the page after the links it will display 5 random comicbook covers.
If you hover over the image the tooltip gives the title and invites customer to click for more info. Under the image is the title.
In sources_custom/miniblocks create a file called random-image.php
USAGE:
on the left upper panel to display "fantasy___science_fiction" book cover:
In the center panel displaying 5 "comic" cover images:
This is actually in the WIKI template... so edit: templates/WIKI_PAGE_SCREEN.tpl
Place at the end, but before the ending DIV:
if PICK is not set this will display a book cover most likely as default is a book (fantasy___science_fiction) but this code: will draw a random number and possibly display a comic picture.
THINGS TO DO:
Wanted to share this and invite people to make it better… You can change this for your own use in yoru site to show random pictures, etc.
I own a bookshop and want to display books on my website, a random book cover throughout the site that points back to the gallery that has more information for the potential customer.
see example usage:
https://nandalow.com/index.php?page=wik ... owse&id=41
Notice the upper left nandalow bookshop box is displaying a book cover. Now scroll down a bit and on the lower left & right it will display a random book or comic cover. In the center of the page after the links it will display 5 random comicbook covers.
If you hover over the image the tooltip gives the title and invites customer to click for more info. Under the image is the title.
In sources_custom/miniblocks create a file called random-image.php
Code: Select all
<?php
// random-image mini block
//
// 1 = fantasy___science_fiction
// 2 =
// 3 = comics
$loop = "1"; $pick = "";
$Product="'fantasy___science_fiction'";
if (mt_rand(1, 150) < 20) { $Product="'comics'"; }
if (isset($map['pick'])) { $pick = $map['pick']; }
if (isset($map['loop'])) { $loop = $map['loop']; }
if ($pick == 3) { $Product="'comics'"; }
if ($pick == 1) { $Product="'fantasy___science_fiction'"; }
for ($x = 1; $x <= $loop; $x++) {
$randomProducts = $GLOBALS['SITE_DB']->query("SELECT id,title,thumb_url FROM new_images WHERE cat like $Product ORDER BY RAND() LIMIT 1");
foreach ($randomProducts as $randomP) {
}
echo '<center><a href="https://nandalow.com/shop/index.php?page=galleries&type=image&id=' . $randomP['id'] . '"><img style="width:100%;" title="FOR SALE: ' . $randomP['title'] . ' is available from The Nandalow Bookshop in Chitose or via mail order. Click for more information & to see other items." src="https://nandalow.com/' . $randomP['thumb_url'] . '"><br>' . $randomP['title'] . '</a></center>';
}
on the left upper panel to display "fantasy___science_fiction" book cover:
Code: Select all
<comcode-box param="Nandalow Bookshop"><input class="cms_keep_ui_controlled" readonly="readonly" size="45" title="[block defer="1" pick="1"]random-product[/block]" type="button" value="random-product Comcode tag (dbl-click to edit/delete)" /></comcode-box>
This is actually in the WIKI template... so edit: templates/WIKI_PAGE_SCREEN.tpl
Place at the end, but before the ending DIV:
Code: Select all
{+START,IF,{$MATCH_KEY_MATCH,_WILD:wiki:id=41}}
{+START,BOX,Nandalow Bookshop,,300}
{$BLOCK,block=random-product,pick=3,loop=6}
{+END}
{+END}
- my wiki ID is 41 so it only shows for this wiki.
- 300 is the width
- pick=3 to show only comic covers
- loop=6 to show 6 random comic cover images....
if PICK is not set this will display a book cover most likely as default is a book (fantasy___science_fiction) but this code:
Code: Select all
if (mt_rand(1, 150) < 20) { $Product="'comics'"; }
THINGS TO DO:
- Use an array for gallery PICK options.
- Be able to select random image from various galleries
- Prevent same image used twice in a loop or same page?