Using category num in URL

14 posts by 4 authors in: Forums > CMS Builder
Last Post: September 15, 2009   (RSS)

Re: [petejdg] Using category num in URL

By Chris - September 2, 2009

Hi petejdg,

That's a little more complicated than the original problem. Attached is my solution to your problem. Hit it with ?category=1 and it'll generate links to select the other records. If you call it without a query string, it'll select the first product in your database with the default sort order and choose the category that product is assigned to.

Hope this helps! Please let me know if you have problems getting this set up.
All the best,
Chris
Attachments:

producthybrid.php 3K

Thanks, that works great. My only problem now is the navigation system, which wigs out cause I am not passing a category through when clicking on the product from the list on the right. I believe I will need to pass the category number, but that ruins the random product code. Is there quick work around for that?

Re: [petejdg] Using category num in URL

By Chris - September 15, 2009 - edited: September 15, 2009

Hi petejdg,

The code I gave you accepts either ?category=1 or ?product_title_1, and knows to get the category num from the product record if no category num is supplied. Here's the relevant part for reference.

...
// if user did not supply a category, assume they supplied a product num and display that product (also, determine category num for right-side list from that product)
else {
list($selectedProductsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$selectedProductsRecord = @$selectedProductsRecords[0]; // get first record
assertRecordExists($selectedProductsRecord);
$catNum = $selectedProductsRecord['category'];
}


Which navigation system is breaking? Can you please post an updated copy of your PHP source code?
All the best,
Chris