USING CATEGORY MENUS - Aug 1st, 2010


The Basics...

If you want to create a series of “Nested” or “Unordered List” menus on your page and display the contents of
that record on the page here’s how.

Create a new section editor called “Category” of the advanced menu type “Category Menu”. (You can call the new
section anything that you want to, but “Category” will work with the demo code below)

Under Admin > Section Editors > Your Category Section > Viewer URLs - set both the List page and Detail page viewer URLs
to /categoryList.php

Now add some Main Category and some Sub Category records, using the “Parent Category” pull down menu to organize
them. (The list will automatically grow with Parent and Child categories after you create new records).

Enter some descriptive text in the content fields, like “this is the description of Main Category 1, this is the
description of sub category 1, etc. so that you can follow the results.

Click on the up and down “order” links to reorder the records. (Changing the order of a parent category moves the
entire category up or down)

Now create a sample List Page viewer called categoryList.php

At the top of your page



<?php

require_once "your server _path /cmsAdmin/lib/viewer_functions.php";

list(
$categoryRecords, $selectedCategory) = getCategories(array(
'Table name' => 'category',
'selectedCategoryNum' => '', // defaults to getNumberFromEndOfUrl()
'categoryFormat' => 'showall', // showall, onelevel, twolevel
));

?>


Use this code where you want the category menu to appear:



<!-- category menu -->
<h3>Nested Menu</h3>
<?php foreach ($categoryRecords as $categoryRecord): ?>

<?php echo str_repeat("&nbsp; &nbsp; &nbsp;", $categoryRecord['depth']); ?>

<?php if ($categoryRecord['_isSelected']): ?><b><?php endif; ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif; ?>
<br />
<?php endforeach; ?>
<!-- /category menu -->


OR - use this code to display the menu in <ul> format:



<!-- unordered list -->
<h3>Unordered List Menu</h3>
<ul>
<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>

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

<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach; ?>
</ul>
<!-- /unordered list -->


And then use this code to display the selected category:



<?php if (!$selectedCategory): ?>
No record selected
<?php endif; ?>

<?php if ($selectedCategory): ?>

<h3><?php echo $selectedCategory['name'] ?></h3>
<?php echo $selectedCategory['content'] ?>

<?php endif; ?>


Those are the basics of using the Category Menu feature that’s built in to Version 1.20 and above.

According to Dave Edis at Interactive Tools, you can control which field is displayed in the URL before the "id" by
setting "filename fields" under: Section Editors > Viewer URLS.

The simplest solution might be to just set this to 'name' instead of 'breadcrumb'

But by default it will use 'breadcrumb' and convert non-word characters to "-" so if you have a breadcrumb of: News :
Technology : Web. So it becomes: News-Technology-Web

You can also create the links in whatever format you like instead of using _link. For example if you created a fieldname
called filename you could have:



<a href="/path/to/viewer.php?<?php echo $categoryRecord['filename'] ?>-<?php echo $categoryRecord['num'] ?>">


To link as:



viewer.php?filename-here-123


You can learn more about using the Category Menu feature from the posts at:

http://www.interactivetools.com/forum/gforum.cgi?post=64259

If any of you have found interesting ways to use this feature, please share them in an e-mail to:

cookbook@thecmsbcookbook.com

Thanks



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service