Need help with categories to show featured items by default

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

Re: [kevbarker] Need help with categories to show featured items by default

By Jason - August 11, 2011

Hi Kevin,

If the name of your check box field is called "featured" you can exploit CMS Builder's autosearching functions like this:

// load records
list($categoriesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'categories',
'selectedCategoryNum' => '', // defaults to getNumberFromEndOfUrl()
'categoryFormat' => 'onelevel', // showall, onelevel, twolevel
));


if (!@$_REQUEST['category']) {
$_REQUEST['featured'] = 1;
}


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


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] Need help with categories to show featured items by default

Jason,

Thanks. I tried the code and it works fine for displaying the featured items when you initially go to the page. However, clicking on the All Products link also shows only the featured items and not ALL of the products. Any ideas? Did I miss something?

Kevin

Re: [kevbarker] Need help with categories to show featured items by default

By Jason - August 12, 2011

Hi Kevin,

What you will need is a way to differentiate between when a person first goes to the page and when someone clicks on All Products.

For example, you can set your all products link to have a variable like this:

<li><a href="?category=all">(All Products)</a></li>

Then we can change your if statement like this:

if (!@$_REQUEST['category']) {
$_REQUEST['featured'] = 1;
}
elseif($_REQUEST['category'] == "all") {
$_REQUEST['category'] = "";
}


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] Need help with categories to show featured items by default

Worked perfectly. Thank you very much for your help!

Kevin