Associating links with specific categories
13 posts by 2 authors in: Forums > CMS Builder
Last Post: July 16, 2012 (RSS)
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!
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
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
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,
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 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: [Jason] Associating links with specific categories
By NigelGordijk - July 12, 2012 - edited: July 12, 2012
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 -->
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 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
Should I have set this up in a different way?
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
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
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
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 13, 2012
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/