Category - How to display the top level items

6 posts by 2 authors in: Forums > CMS Builder
Last Post: January 10, 2013   (RSS)

Hi Jac,

You could change your $rightMenu getRecords function so that it only gets the top level items like this:

list($rightMenu, $categoryMetaData) = getCategories(array(
'tableName' => 'category',
'loadUploads' => true,
'rootCategoryNum' => 0,
'categoryFormat' => 'onelevel'
));

I've set the rootCategoryNum to zero, so the function will start looking for items at the very top level.

The categoryFormat is set to onelevel, so it will only return the level you have selected.

You might be able to remove the $categoryRecords getRecords function, but I'm not sure if it is used anywhere else on your page. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi Gerg

Nice now! Thanks!!

Jac

-Jax H.

Hi Gerg

One problem.

The top level items is fine on the first level page.

but when go to secand and thried level.

Top level items also display on other level.

Jac

-Jax H.

Hi Jac,

Sorry, I thought you wanted to create a completetly seperate page. If you want to display all of the parent categorys if no sub category is selected on the same page, I would do something like this:

/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

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

// Get the last number from the URL, if there isn't one there set the number as zero. 

$mainCat =  intval(getLastNumberInUrl());

// load detail record from 'category' 

list($categoryRecords, $categoryMetaData) = getRecords(array( 
'tableName' => 'category',
'where' => whereRecordNumberInUrl(1), // If no record # is specified then latest record is shown 
'loadUploads' => true, 
'allowSearch' => false, 
'limit' => '1', 
)); 
$detailRecord = @$categoryRecords[0]; // get first record 
if (!$detailRecord) { dieWith404("Record not found!"); } // show error message if no record found 

// load list records from 'category' 
list($leftMenu, $categoryMetaData) = getCategories(array( 
'tableName' => 'category', 
'loadUploads' => true, 
'categoryFormat' => 'twolevel' 
)); 

//Show either level one or two category pages depending on if a there is a number in the URL
list($rightMenu, $categoryMetaData) = getCategories(array( 
'tableName' => 'category', 
'loadUploads' => true, 
'rootCategoryNum' =>  $mainCat
'categoryFormat' => 'onelevel' 
));


So if there isn't a number in the URL, the rootCategoryNum will default to 0, and the page will only display top level items. You should be able to keep the same body code as you used last time.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi Gerg

It's all good now!

Nice job, Thanks!

Jac

-Jax H.