Help with category menu

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 4, 2012   (RSS)

By KCMedia - January 3, 2012

Hi all

i have this category list on the home page at this site http://www.actionmc.com.au/beta/index.php for the accessories and i need to be able to have it built into cmsb i have created a category menu section but i cant get it work any ideas on what i need to do to make it work like i have it designed.

attached in the cmsb code and also the includes file for the design of the layout.

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/httpdocs/','','../','../../','../../../');
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 records
list($accessories_menuRecords, $accessories_menuMetaData) = getRecords(array(
'tableName' => 'accessories_menu',
));

?> <!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Accessories Menu - List Page Viewer</h1>
<?php foreach ($accessories_menuRecords as $record): ?>
Record Number: <?php echo $record['num'] ?><br/>
Parent Category: <?php echo $record['parentNum'] ?><br/>
Name: <?php echo $record['name'] ?><br/>
Link: <?php echo $record['link'] ?><br/>
_link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>

<hr/>
<?php endforeach ?>

<?php if (!$accessories_menuRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->
Thanks



Craig

KC Media Solutions

www.kcmedia.biz
Attachments:

accessories-list-inc.php 2K

Re: [kcmedia] Help with category menu

By (Deleted User) - January 4, 2012

Hello Craig,

The first thing to look at is how the records are being retrieved - currently you're using "getRecords" which is perfect for general data but for categories there is a function "getCategories" that retrieves the data from the category table and preps it for use in creating a menu:
list($allCategories, $selectedCategory) = getCategories(array(
'tableName' => 'accessories_menu',
'categoryFormat' => 'twolevel', // showall, onelevel, twolevel, breadcrumb
));


Now we can use the $allCategories array to create the menu:
<ul>
<?php foreach ($allCategories as $category): ?>
<?php echo $category['_listItemStart'] ?>

<?php if ($category['_isSelected']): ?>
<b><a href="<?php echo $category['_link'] ?>"><?php echo $category['name'] ?></a></b>
<?php else: ?>
<a href="<?php echo $category['_link'] ?>"><?php echo $category['name'] ?></a>
<?php endif; ?>

<?php echo $category['_listItemEnd'] ?>
<?php endforeach; ?>
</ul>


Setting "categoryFormat" to "twolevel" will show the root category (eg APPAREL) and then all the children of that category in an list 'below' it.

As long as the detail and viewer pages are set in cmsb (Admin->Section Editors->accessories_menu->Viewer Urls) then the links will automatically be set up.

Hope this helps,

Tom