Category Links
2 posts by 2 authors in: Forums > CMS Builder
Last Post: December 13, 2011 (RSS)
By Kenny - December 13, 2011
I know I have done this plenty of times before, but I am having so many problems with trying to get URL searching to work with what I am doing.
I have a products section that list various products as normal (tile, description, etc.) I have another section called categories, where the client can start adding categories.
In the products section, I have a dropdown list that displays the available categories.
On the page, I want to list all of the categories and when you click on one, it will take you to the products page where any product in that category will be displayed.
The link looks like this:
<a href="../products.php?category=<?php echo $record['num'] ?>"><?php echo $record['title'] ?></a>
which translates into this: /products.php?category=3
I want the url to look like this for search engine optimization purposes:
/products.php?category=Cattle Guards
So I tried putting:
<a href="../products.php?category=<?php echo $record['title'] ?>"><?php echo $record['title'] ?></a>
When I do that, no products come up.
What am I missing?
I have a products section that list various products as normal (tile, description, etc.) I have another section called categories, where the client can start adding categories.
In the products section, I have a dropdown list that displays the available categories.
Get options from a MySQL Database
Section Tablename: category
Use this field for option values: num
Use this field for option labels: title
On the page, I want to list all of the categories and when you click on one, it will take you to the products page where any product in that category will be displayed.
The link looks like this:
<a href="../products.php?category=<?php echo $record['num'] ?>"><?php echo $record['title'] ?></a>
which translates into this: /products.php?category=3
I want the url to look like this for search engine optimization purposes:
/products.php?category=Cattle Guards
So I tried putting:
<a href="../products.php?category=<?php echo $record['title'] ?>"><?php echo $record['title'] ?></a>
When I do that, no products come up.
What am I missing?
Re: [Kenny] Category Links
By Jason - December 13, 2011
Hi Kenny,
The issue here is that the category field in your products section is only storing the category record number, not the title. If you want to use the title you have a couple of options:
1) Change the option value from num to title for your drop down. You'll have to re-associate all your products to categories, but after that, you can search for a category by title instead of num. If the name of a category ever changes, however, these associations will break.
2) Another option would be to do your search manually, first getting the category record then using that num in your products search. NOTE: for this to work well, a category title will have to be unique. This example also assumes your using CMSB version 2.08 or higher:
Hope this helps get you started.
The issue here is that the category field in your products section is only storing the category record number, not the title. If you want to use the title you have a couple of options:
1) Change the option value from num to title for your drop down. You'll have to re-associate all your products to categories, but after that, you can search for a category by title instead of num. If the name of a category ever changes, however, these associations will break.
2) Another option would be to do your search manually, first getting the category record then using that num in your products search. NOTE: for this to work well, a category title will have to be unique. This example also assumes your using CMSB version 2.08 or higher:
$options = array(
'tableName' => 'products',
);
if (@$_REQUEST['category']) {
$category = mysql_get('category', null, "title = '".mysql_escape(@$_REQUEST['category'])."'");
if (!$category) { die("Error! Category Not Found!"); }
$options['allowSearch'] = false;
$options['where'] = "category = '".mysql_escape($category['num'])."'";
}
list($productRecords, $productMetaData) = getRecords($options);
Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/