Category - How to display the top level items

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

By esupport - January 9, 2013

Hi, 

There are 3 levels on my category.

On the first category page.

It should display  top level items. 

Now the page is display the secand level list.

How can I display the top level?

Here is the page:

http://174.132.79.189/~quanmax/en/category-list.php

Header code:

<?php
/* 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."); }

// 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' 
)); 

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


?>

Body:

<?php foreach ($rightMenu as $listRecord): ?>

<table border="0" cellspacing="0" cellpadding="0" width="700">
<span 
id="news_list_lab">
<tbody>
<tr>
<td width="185" valign="top" class="content_s_000"><?php foreach ($listRecord['images'] as $index => $upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" 
alt="<?php echo htmlencode($productsRecord['title']) ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" hspace="20" /><br/>
<?php endforeach ?></td>
<td align="left" valign="top" class="content"><b><a <?php echo ($listRecord['depth']+1)*10; ?>px;" href="<?php if($listRecord['depth'] == '0'){ 
echo 'category-list.php?num='.$listRecord['num']; 
}elseif($listRecord['depth'] == '1'){ 
echo 'category-list.php?num='.$listRecord['num']; 
}elseif($listRecord['depth'] == '2'){ 
echo 'products-detail.php?num='.$listRecord['num']; 

?>" > <?php echo htmlencode($listRecord['name']) ?></a></b> <?php echo $listRecord['intro']; ?></td>
</tr>
<tr>
<td colspan="2" align="right" class="line_h_dot_black"><a style="margin-left:<?php echo ($listRecord['depth']+1)*10; ?>px;" href="<?php if($listRecord['depth'] == '0'){ 
echo 'category-list.php?num='.$listRecord['num']; 
}elseif($listRecord['depth'] == '1'){ 
echo 'category-list.php?num='.$listRecord['num']; 
}elseif($listRecord['depth'] == '2'){ 
echo 'products-detail.php?num='.$listRecord['num']; 

?>" ><img 
class="banner_line_no" hspace="0" alt="See More!" vspace="5" 
src="images/share/button_more.gif" width="41" 
height="11" /></a></td>
</tr>
</tbody>
</span>
</table>

<?php endforeach ?>

Thanks!

Jac

-Jax H.
Attachments:

category-list_001.php 42K

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 Gerg

It's all good now!

Nice job, Thanks!

Jac

-Jax H.