My SellerDeck Account | Newsletter | Free Trial

Community and Knowledge Base

  #1  
Old 22-Nov-2009, 05:18 PM
KB KB is offline
Administrator
Join Date: Nov 2009
Posts: 1,012
Thanks: 0
Thanked 34 Times in 29 Posts
How can I generate a random product list on my home page?

We first store the HTML of the Mini Best Seller layout from all products into an array.

Then later display 4 at random.

<!-- Here we fill a PHP array with snippets of HTML from all products -->
<actinic:block php="true">unset($allproducts);</actinic:block>
<actinic:block type="EntireSectionList">
<actinic:block type="ProductList" php="true">
if ( <actinic:variable name="ProductType" /> == 0 )
{
$allproducts[] = <<<ENDOFCODE
<actinic:variable name="BestSellerItem" value="Mini Best Seller Layout" encoding="perl" />
ENDOFCODE;
}
</actinic:block>
</actinic:block>

<!-- Here we output 4 random products -->
<actinic:block php="true">
for ( $i=1; $i<=4; $i++ )
{
echo '<br clear="all" />' . $allproducts[mt_rand(0, count($allproducts) - 1)];
}
</actinic:block>


You could put the first bit (or all of it) into a layout that's processed only once (like Brochure Home page). The second snippet could be on every page as the PHP array should be populated then.

Kindly provided by Norman Rouxel from Drillpine
Reply With Quote
  #2  
Old 03-Aug-2017, 03:52 PM
graphicz's Avatar
graphicz graphicz is offline
Registered User
Join Date: May 2007
Full Name: Jonathan Chappell
Posts: 724
Thanks: 58
Thanked 91 Times in 71 Posts
This continues to work very well (v16 now) but with large sites can significantly lengthen the time to take snapshots and for uploading the site.

I have played around with the invariant property and this seems to work to speed upload and snapshot without hindering the generation process:

Code:
<actinic:block invariant="true" >
<!-- Here we fill a PHP array with snippets of HTML from all products -->
<actinic:block php="true">unset($allproducts);</actinic:block>
<actinic:block type="EntireSectionList" >
<actinic:block php="true" type="ProductList" >
if ( <actinic:variable name="ProductType" /> == 0 )
{
$allproducts[] = <<<ENDOFCODE
<actinic:variable encoding="perl" value="forMMII" name="BestSellerItem" />
ENDOFCODE;
}
</actinic:block>
</actinic:block>
</actinic:block>
An invariant block is wrapped around the whole expression.
Site in question had some 2000 products and without the invariant block upload was 30mins coming down to five minutes with the block.

Thanks to Norman
__________________
Jonathan Chappell
Website Designer
SellerDeck Website Designer
Actinic to SellerDeck upgrades
Graphicz Limited - www.graphicz.co.uk
Reply With Quote
The Following User Says Thank You to graphicz For This Useful Post:
Duncan Rounding (04-Aug-2017)
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 12:37 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.