Category selection populates sub categories

20 posts by 3 authors in: Forums > CMS Builder
Last Post: March 16, 2012   (RSS)

By benedict - March 6, 2012

OK, I think I;ve completely painted myself into a corner here with these breadcrumbs. Hope you can help. The example of category down to product detail page is this:

Home > Agriculture > All Boxes > Oyster Box
or;
Home > Category > Sub Category > Product Detail

1. Top Level Categories - no problem with breadcrumbs as I just repeat the title in the breadcrumb and it does not need to be hyperlinked (only home does) - i.e. Home > Agriculture

2. Sub Category Page - I can get the text to present correctly but can not get the links to go to the correct page in the breadcrumbs.

I am using this in the header:

// load records
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => "sub_category = '". intval($product_sub_categoriesRecord['num']) ."'" ,
));


and this is in breadcrumbs:

<ul class="breadcrumbs">
<li><a href="index.php">Home</a></li>
<li><a href="#"><?php echo $product_sub_categoriesRecord['category:label'] ?></a></li>
<li><?php echo $product_sub_categoriesRecord['title'] ?></li>
</ul>


I don;t know what code to put for the link for the sub category label.

3. Product detail pages - I can not get the labels correct (showing wrong sub category) nor links for the subcategories.

I am using this in the header:

// load records
list($product_sub_categoriesRecords, $product_sub_categoriesMetaData) = getRecords(array(
'tableName' => 'product_sub_categories',
'limit' => '1',
));
$product_sub_categoriesRecord = @$product_sub_categoriesRecords[0]; // get first record
$subCategories = mysql_select("product_sub_categories");
$subCategoryNumToTitle = array_combine(array_pluck($subCategories, 'num'), array_pluck($subCategories, 'title'));


and this in the body:

<ul class="breadcrumbs">
<li><a href="#">Home</a></li>
<li><a href="#"><?php echo $productsRecord['category:label'] ?></a></li>
<li><a href="#"><?php echo $subCategoryNumToTitle[$product_sub_categoriesRecord['category']]; ?></a></li>
<li><?php echo $productsRecord['title'] ?></li>
</ul>


Any ideas what I am doing wrong?

Thanks in advance.

Re: [benedict] Category selection populates sub categories

By Jason - March 8, 2012

Hi,

For the first problem, if you're trying to link to the $product_sub_categoriesRecord, you should be able to use the _link pseudo field.

For example:

<ul class="breadcrumbs">
<li><a href="index.php">Home</a></li>
<li><a href="#"><?php echo $product_sub_categoriesRecord['category:label'] ?></a></li>
<li><a href = "<?php echo $product_sub_categoriesRecord['_link'];?>"><?php echo $product_sub_categoriesRecord['title'] ?></a></li>
</ul>


Does this seem like what you're looking for?


For the problem using subCategoryNumToTitle, is your code producing an error, or just outputting the wrong label?

The subCategoryNumToTitle variable pulls from the product_sub_categories section. Which section does the category field of the $product_sub_categoriesRecord variable pull from?

Let me know and we'll see what we can do.

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/

By benedict - March 13, 2012

Thanks Jason,

Actually, regarding the first problem, it is the second item, not the third that I am trying to work out the link for i.e.:

<ul class="breadcrumbs">
<li><a href="index.php">Home</a></li>
<li><a href="#"><?php echo $product_sub_categoriesRecord['category:label'] ?></a></li>
<li><a href = "#"><?php echo $product_sub_categoriesRecord['title'] ?></a></li>
</ul>


Any ideas?

For my second problem, no, no error, just the wrong label.

Which section does the category field of the $product_sub_categoriesRecord variable pull from?


The category field of $product_sub_categoriesRecord pulls from the product_categories sections

The 3 sections I'm using are product_categories, product_sub_categories and products.

Thanks in advance.

Re: [benedict] Category selection populates sub categories

By Jason - March 13, 2012

Hi,

I'm not what the name of your page that you want to link to is, or how it's set up, but you should be able to manually create a link.

For example:

<ul class="breadcrumbs">
<li><a href="index.php">Home</a></li>
<li><a href="categoryDetail.php?<?php echo $$product_sub_categoriesRecord['category'];?>"><?php echo $product_sub_categoriesRecord['category:label'] ?></a></li>
<li><a href = "#"><?php echo $product_sub_categoriesRecord['title'] ?></a></li>
</ul>


For the second problem, what's happening is the subCategoryNumToTitle variable pulls from the product_sub_categories section, where you want labels from the product_categories section. You'll want to set up a second variable like this:

$categories = mysql_select("product_categories");
$categoryNumToTitle = array_combine(array_pluck($categories, 'num'), array_pluck($categories, 'title'));


You can then output the label like this:

<li><a href="#"><?php echo $categoryNumToTitle[$product_sub_categoriesRecord['category']]; ?></a></li>

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/

By benedict - March 14, 2012

OK, great, everything is working, except for the label for the subcategory on the product detail page.

I got it wrong when I said I wanted labels from the categories section [blush]. I want the labels from the product_sub_categories section (the 'title' field of that section, to be specific).

My code at the moment is:
// load records
list($product_sub_categoriesRecords, $product_sub_categoriesMetaData) = getRecords(array(
'tableName' => 'product_sub_categories',
'limit' => '1',
));
$product_sub_categoriesRecord = @$product_sub_categoriesRecords[0]; // get first record
$subCategories = mysql_select("product_sub_categories");
$subCategoryNumToTitle = array_combine(array_pluck($subCategories, 'num'), array_pluck($subCategories, 'title'));


Thanks for all your efforts thus far...

Re: [benedict] Category selection populates sub categories

By benedict - March 14, 2012

And my code in the body is:

<ul class="breadcrumbs">
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li><a href="polystyrene-product-cat.php?<?php echo $productsRecord['category'] ?>"><?php echo $productsRecord['category:label'] ?></a></li>
<li><a href="polystyrene-product.php?<?php echo $productsRecord['sub_category'] ?>"><?php echo $subCategoryNumToTitle[$product_sub_categoriesRecord['category']]; ?></a></li>
<li><?php echo $productsRecord['title'] ?></li>
</ul>

Re: [benedict] Category selection populates sub categories

By Jason - March 14, 2012

Hi,

You're really close. You need to be using the sub_category field as the index of your label array though.

Try this:

<li><a href="polystyrene-product.php?<?php echo $productsRecord['sub_category'] ?>"><?php echo $subCategoryNumToTitle[$product_sub_categoriesRecord['sub_category']]; ?></a></li>
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

By benedict - March 14, 2012

Not quite, I get this:

Notice: Undefined index: sub_category in /home/jpoly/public_html/foam-polystyrene.php on line 56 Notice: Undefined index: in /home/jpoly/public_html/foam-polystyrene.php on line 56

Re: [benedict] Category selection populates sub categories

By Jason - March 15, 2012

Hi,

We keep getting our variable names mixed up. :)

This should be it:

<li><a href="polystyrene-product.php?<?php echo $productsRecord['sub_category'] ?>"><?php echo $subCategoryNumToTitle[$productsRecord['sub_category']]; ?></a></li>
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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