Associating links with specific categories

13 posts by 2 authors in: Forums > CMS Builder
Last Post: July 16, 2012   (RSS)

I have a site section where the product categories can be created by my client and shown as link on a page: http://www.heritageacresnutrition.com/products.php. These are displaying correctly, but when you click on a link it shows all of the product pages, not jut those within the selected category. http://www.heritageacresnutrition.com/productsSubcategory.php?main_category=4. If the user chooses, say, Wild Bird Food, I'd like to show only those product pages.

Also, is there a way to show the product category as a subheading only once on this page, rather than repeating it before each product link?

Thanks!
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Associating links with specific categories

By Jason - July 11, 2012

Hi Nigel,

The problem here is that your getRecords() call doesn't do a search. Try this:

list($our_productsRecords, $our_productsMetaData) = getRecords(array(
'tableName' => 'our_products',
'loadUploads' => true,
'allowSearch' => false,
'where' => "category = '".intval(@$_REQUEST['main_category'])."'",
));


In terms of only outputting the the category name once, you can use this same technique to only retrieve a single category record, then display this outside of the foreach loop.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Associating links with specific categories

Hi, Jason.

I gave that a try, but now nothing is showing up. Have I done this correctly?

http://www.heritageacresnutrition.com/products.php and http://www.heritageacresnutrition.com/productsSubcategory.php?main_category=4

Thanks,
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Associating links with specific categories

By Jason - July 12, 2012

Hi Nigel,

The looks correct. The issue may be in your "category" field in the product section. Are you using "num" as the value?
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [NigelGordijk] Associating links with specific categories

By Jason - July 12, 2012

Hi,

The code you posted in your previous post is correct, I think the issue is how you have the category field set up in the CMS. If you edit that field, what do you see under option values?
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Associating links with specific categories

The category field is for text, as that's where the client will be adding further categories. I've attached screen shots for the Product Categories and Our Products sections of CMSB.

Should I have set this up in a different way?
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Associating links with specific categories

By Jason - July 12, 2012

The category field in the our_products section is set up as a list field. In the example code I gave you, I assumed that the option value of that list field used the num field from the category section.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Associating links with specific categories

Aha! Now I understand! :-) I had the "Use this field for option values" set as "title", not "num". I've corrected that and not it seems to be working. Thanks for clarifying that.

Is there a way to get the category heading to appear only once, rather than repeating above the individual page links?

http://www.heritageacresnutrition.com/products.php

http://www.heritageacresnutrition.com/productsSubcategory.php?main_category=4
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net
Attachments:

cms-our-products2.gif 25K

Re: [NigelGordijk] Associating links with specific categories

By Jason - July 13, 2012

Hi Nigel,

Since you have the record number of the category in your URL, you should be able to retrieve the associated category record. You can then output this once before your foreach loop, and only output your product names inside the foreach loop.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/