Forums / Templates, Stylesheets, Page Layout / Random products from category & subcategory

Random products from category & subcategory

Locked

Views: 1,017

Results 1 to 2 of 2
This thread is locked. New replies are disabled.
7 Feb 2008, 11:47 AM
#1
christoph_lutz avatar

christoph_lutz

New Zenner

Join Date:
Jun 2007
Posts:
24
Plugin Contributions:
0

Random products from category & subcategory

Hi,

I am looking at creating a function that pulls out x number of products randomly from the current category and its subcategories. I want to write some php/sql code that gives me an the title, the thumnail image and the price as well as the link through to the full product. I have looked at featured product sidebox and similar but they rely on products being set up as featured. I would like to write it independently and also get products from subcategories. So

  • can I write a query that gets me all products from a given category and its subcategories?

I can then randomly select from the returned recordset although pointers as how to do that would be appreciated

Thanks

Christoph

7 Feb 2008, 12:16 PM
#2
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Random products from category & subcategory

It can be done but is fairly complicated. Pulling this information out of the database is fairly straightforward and you can order it randomly and limit it to the number you need in the order section of your MySQL query.

The challenge is compiling the list of categories as you would need to do a recursive tree walk to get the subcategories and any subcategories that they might have, and so on. I recommend looking at how the categories sidebox is built to see how to do this.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)