Get articles from different tables (subcategories)

4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 18, 2013   (RSS)

By Jesus - September 18, 2013

Hello,

Here's another issue I need to get solved... will try my best to explain this properly.

I've a products category with 3 articles on it. Each article represents one product category.

Each product category has their own table (subcategories).

I want my detail page on products to display the article list for each particular subcategory.

Something like:

/products/category-one/

/products/category-two/

/products/category-three/

Where on category-one file I'll display the article list from sub-category-one, on category-two file I'll display the article list from sub-category-two and on category-three file I'll display the article list from sub-category-three. 

The thing here its that I need an IF statement on my detail page on products so based on which category I'm it will display the proper subcategory list.

I hope I explain this properly and it is clear. Thanks in advance for your help!

Jesus

By Jesus - September 18, 2013

I found a way to do this, I don't know if that's the best possible way to do it, but it works for me :)

On my products table, I create a list field with 4 options (select). Those options are SUB1, SUB2, SUB3, and SUB4 (you can name it in any way, just be sure to use the same name on the IF Statement below.

Then on my detail page I use this code:

                        <h2>Products</h2>
                        <ul class='left_navigation'>
                         <?PHP if ($productsRecord['category'] == "SUB1"): ?>
                         <?php foreach ($subcategory1Records as $record): ?>
                             <li class="page_item page-item-54"><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a><div></div></li>
                         <?php endforeach ?>
                         <?PHP endif ?>

                         <?PHP if ($productsRecord['category'] == "SUB2"): ?>
                         <?php foreach ($subcategory2Records as $record): ?>
                             <li class="page_item page-item-54"><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a><div></div></li>
                         <?php endforeach ?>
                         <?PHP endif ?>

                         <?PHP if ($productsRecord['category'] == "SUB3"): ?>
                         <?php foreach ($subcategory3Records as $record): ?>
                             <li class="page_item page-item-54"><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a><div></div></li>
                         <?php endforeach ?>
                         <?PHP endif ?>

                         <?PHP if ($productsRecord['category'] == "SUB4"): ?>
                         <?php foreach ($subcategory4Records as $record): ?>
                             <li class="page_item page-item-54"><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a><div></div></li>
                         <?php endforeach ?>
                         <?PHP endif ?>
                        
                        </ul>

This worked fine for what I'm looking for. If anyone knows a better way to do this, it will be great if he can share it! :)

Jesus

By Jesus - September 18, 2013

Munch, much better :)

Thanks!!