Creating a side menu with categories of products

12 posts by 2 authors in: Forums > CMS Builder
Last Post: August 25, 2010   (RSS)

By fsardoni - August 24, 2010

Hi I need some help in creating a side menu with categories of products.
I have built it following some directions from this forum but I am having problems with the following error:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/g/o/f/gofgof/html/productsList.php:29) in /home/content/g/o/f/gofgof/html/includes/productnavigation.php on line 1

Can someone please help me or just point me to the right thread in this forum?
Many thanks in advance.

Re: [fsardoni] Creating a side menu with categories of products

By fsardoni - August 24, 2010

Ok I found one solution: removing the line 1 :
<?php header('Content-type: text/html; charset=utf-8'); ?>
of the navigation fixed it.

Re: [fsardoni] Creating a side menu with categories of products

By fsardoni - August 24, 2010

Now I can't seem to have the categories finding and displaying the proper products. Can anyone help? Thank you

Re: [fsardoni] Creating a side menu with categories of products

By Chris - August 24, 2010

Hi fsardoni,

Can you provide more information on the problem? A link to your page, a description of what you're getting vs. what you expect, and an attachment of your full PHP source code would be very helpful. :)
All the best,
Chris

Re: [chris] Creating a side menu with categories of products

By fsardoni - August 24, 2010 - edited: August 24, 2010

Hi Chris, thank you for your help:
The link is: http://www.greetingsoffaith.com/productsList.php
Please find all my files attached.
I am also having this issue where the products are displaying a number instead of the category name... It's a mess. Sorry and thank you.

PS.forgive the look it is not css stylized yet.

Re: [chris] Creating a side menu with categories of products

By fsardoni - August 25, 2010

Hi Chris, where do I change that to reflect the field "categories"??
Thank you.
Yes I did check the Sub-categories Tutorial, infact some of the code is lifted from there.

Re: [fsardoni] Creating a side menu with categories of products

By fsardoni - August 25, 2010

Hi Chris another issue I discovered is that when I am clicking on my side navigation links while in the productsList.php page I get all the records always. When I then click on the product that was found in the productsList.php I go to the productDetail.php page which is correct but when I then click back on any other link the url changes to:
http://www.greetingsoffaith.com/productDetail.php?category=32
instead of showing me or bringing me back to:
http://www.greetingsoffaith.com/productsList.php?category=32:

Why is that? and Or should it be that way?
Thank you

Re: [fsardoni] Creating a side menu with categories of products

By Chris - August 25, 2010 - edited: August 25, 2010

Hi fsardoni,

You're getting all the records because category=32 is ignored by CMS Builder since there is no field called "category".

Your other issue is also caused by the URLs: they're relative to the current document since they start with "?". You'll want to explicitly link to /productsList.php.

You can change the URLs by modifying this line in productnavigation.php:

<a href="?category=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>

...to:

<a href="/productsList.php?categories=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>

I hope this helps! Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Creating a side menu with categories of products

By fsardoni - August 25, 2010

Ok! That fixed it for the most part. Thank you. Now I am getting this error message:

Notice: Undefined variable: categoryRecord in /home/content/g/o/f/gofgof/html/includes/productnavigation.php on line 27 (All Products)

<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/content/g/o/f/gofgof/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."); }

list($categoriesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'categories',
));

list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
));

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
</head>
<body>
<ul>
<li><a href="/productsList.php?categories=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?>(All Products)</a></li>
<?php foreach ($categoriesRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>

<?php if ($categoryRecord['_isSelected']): ?><b><?php endif ?>
<a href="/productsList.php?categories=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif ?>

<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach ?>
</ul>
</body>
</html>