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: [Jason] Associating links with specific categories

By NigelGordijk - July 12, 2012 - edited: July 12, 2012

Sorry, where should that go?

This is the code generated by CMSB for the products list page, amended to include the categories which are added via CMSB, too:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/heritage/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records from 'our_products'
list($product_categoriesRecords, $product_categoriesMetaData) = getRecords(array(
'tableName' => 'product_categories',
'loadUploads' => true,
'allowSearch' => false,
));

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

?>
<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Our Products - List Page Viewer</h1>
<?php foreach ($our_productsRecords as $record): ?>
Record Number: <?php echo htmlencode($record['num']) ?><br/>
Category (value): <?php echo $record['category'] ?><br/>
Category (label): <?php echo $record['category:label'] ?><br/>
Title: <?php echo htmlencode($record['title']) ?><br/>
Content: <?php echo $record['content']; ?><br/>
_link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>
<hr/>
<?php endforeach ?>

<?php if (!$our_productsRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->

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,

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/