You are here:  » random products on other pages

Support Forum



random products on other pages

Submitted by paullas on Mon, 2008-10-27 00:24 in

hi

not sure if this has been asked but i cant find it.

is there a way to list say 20 random products on other web pages, so everytime a user click on a paget they get a different 20 products every time. the pages are all on same server

thanks

paul

Submitted by support on Mon, 2008-10-27 09:25

Hi Paul,

Are these other pages that are not part of Price Tapestry; or do you mean other Price Tapestry pages?

Cheers,
David.

Submitted by paullas on Mon, 2008-10-27 11:22

hi

the pages are in different folders on the site, so..

price tapestry is installed in folder PT
i have pages in the folder bargains and folder latest search so i am wanting to display say 20 random images on the index page in the bargains and latest search folder.

thanks

paul

Submitted by support on Mon, 2008-10-27 12:42

Hi Paul,

No problem - I recently posted a featuredExternal script in the following thread:

http://www.pricetapestry.com/node/2289

...so i've just modified that quickly in the same way that I describe how to convert featured products into random products.

randomExternal.zip

Upload randomExternal.php to the Price Tapestry folder, and then include anywhere else on your site using:

<?php
  $common_baseHREF 
"http://www.example.com/pricetapestry/";
  
$common_path "/path/to/pricetapestry/";
  require(
$common_path."randomExternal.php");
?>

See the detailed instructions at the top of the other thread for setting $common_path etc. if you're not sure of the actual server path to your www directory...

Cheers,
David.

Submitted by paullas on Mon, 2008-10-27 13:48

works a treat, thanks...

another thing if thats ok. how would i go about listing them in text order and not display a pic. so the layout i am looking for is like this:

Product Image (thumbnail) | Product Name | Brief Description | Price | link to product | visit store

thank again

paul

Submitted by support on Mon, 2008-10-27 13:52

Hi Paul,

Currently, randomExternal.php calls in the featured products HTML module with this line:

if (isset($featured)) require($common_path."html/featured.php");

...so the first thing to do would be to make a copy of html/featured.php and save it as something like html/random.php. Then change the line shown above to:

if (isset($featured)) require($common_path."html/random.php");

Then you can start playing around with html/random.php to create the random products display as required...

Cheers,
David.

Submitted by babrees on Wed, 2010-05-19 18:53

Hi David

I tried this on the new version with Word Press but it didn't work. I see that the above link to the file download no longer works.

Is there a new version of randomExternal.php?

Cheers

---------
Jill

Submitted by support on Thu, 2010-05-20 11:30

Hi Jill,

I've reinstated the file (for latest version of Price Tapestry) here.

It will default to 3 random products, which you can override by adding the following to your calling code:

  $common_randomCount = 5;

(or whatever count you want - add the line just before the require() statement)

Cheers,
David.

Submitted by babrees on Thu, 2010-05-20 12:00

Thanks David!

---------
Jill

Submitted by babrees on Tue, 2010-06-01 07:11

Is it possible to add a keyword to this? So, for instance, I can have 3 random "pink dress" ??

---------
Jill

Submitted by support on Tue, 2010-06-01 08:50

Hi Jill,

Sure - in your randomExternal.php file you'll find the SQL that selects the products on line 60 as follows:

  $sql = "SELECT normalised_name,1 AS sequence FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT ".$common_randomCount;

...REPLACE that with something like:

  if ($common_randomKeywords)
  {
    $wheres = array();
    $words = explode(" ",$common_randomKeywords);
    foreach($words as $word)
    {
      $wheres[] = " (name LIKE '%".database_safe($word)."%' OR description LIKE '%".database_safe($word)."%') ";
    }
    $where = implode(" AND ",$wheres);
    $sql = "SELECT normalised_name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE ".$where." ORDER BY RAND() LIMIT ".$common_randomCount;
  }
  else
  {
    $sql = "SELECT normalised_name,1 AS sequence FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT ".$common_randomCount;
  }

...and then add

  $common_randomKeywords = "pink dress";

Hope this helps!

Cheers,
David.

Submitted by babrees on Tue, 2010-06-01 11:13

Hi David, Thanks but unfortunately that doesn't seem to work.
---------
Jill

Submitted by support on Tue, 2010-06-01 18:58

Hi Jill,

I can't see anything immediately wrong with the code - I just modified the version above to include the description if that might be the issue.

Otherwise, could you confirm that a normal randomFeatured.php (without keywords) call still works, and perhaps email me your featuredExternal.php, a copy of the calling code and link if possible to one of the products that should match the random selection and I'll check it all out for you...!

Cheers,
David.