Category Menus HELP

7 posts by 3 authors in: Forums > CMS Builder
Last Post: March 3, 2014   (RSS)

By zaba - February 25, 2014

I'm baffled by how this works.

Firstly If I create a new Category Menu, based on 2 levels, Parent Level and Child Level. How do I get it to output to display like the following when parsed?

Quite baffled as to what the code would be.

<ul id="menu">


<li><a href="#">PARENT A</a>
    <ul>    
    <li><a href="#">PARENT A CHILD 1</a></li>
    <li><a href="#">PARENT A CHILD 2</a></li>
    <li><a href="#">PARENT A CHILD 3</a></li>
   </ul>
</li>
<li><a href="#">PARENT B</a>
    <ul>
    <li><a href="#">PARENT B CHILD 1</a></li>
    <li><a href="#">PARENT B CHILD 2</a></li>
    <li><a href="#">PARENT B CHILD 3</a></li>
    </ul>
</li>

<li><a href="#">PARENT C</a>
    <ul>
    <li><a href="#">PARENT C CHILD 1</a></li>
    <li><a href="#">PARENT C CHILD 2</a></li>
    <li><a href="#">PARENT C CHILD 3</a></li>
    </ul>
</li>
</ul>

Secondly I will then be creating individual tables (some will be multi pages and some will be single pages for each of the Categories/sub categories above) 

How would I then populate the <a href above to marry up to the correct tables?

Sorry Ive searched the forum and can't find anything that will solve this for me.

By zaba - February 26, 2014

Hi Greg,

Yes I think I can follow that, each of the pages will have different layouts and data so there is a need to create different tables for the different types. I'll just add a link field in to marry those up, seems logical.

The only other thing I need to clarify is that on each of the Parent Section Pages I want to show the child links on that particular page. (I am using the main menu as pull downs which I have working)

So when you click on one of the linked pages it will show the parent heading and the child links for that particular page/section.

thanks

Hi zaba,

You can display only the child links for a particular category using the rootCategoryNum in your getCategories function:

    'rootCategoryNum' => '8'

When you pass in a num value this way, only items below this in the category menu will be returned.

Let me know if you need an example of how this could be implemented.

Cheers!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By zaba - February 26, 2014

An example would be most helpful, thanks

By Chris - February 28, 2014

Hi zaba,

Assuming you're using detail page URLs (which have the record number in the URL) to select your Parent Section Pages, you can use getLastNumberInUrl() to get the record number to use as a rootCategoryNum.

Here's an example:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?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('','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
  
  $parentNum = getLastNumberInUrl(0);
 
  // get parent category
  list($parentCategoryRecords) = getRecords(array(
    'tableName'   => 'category',
    'where'       => mysql_escapef('num = ?', $parentNum),
    'allowSearch' => false,
  ));
  $parentCategory = @$parentCategoryRecords[0];
  if (!$parentNum || !$parentCategory) { die("Parent Category not found"); }
  
  // load child categories
  list($categoryRecords, $selectedCategoryRecord) = getCategories(array(
    'tableName'       => 'category',
    'loadUploads'     => true,
    'rootCategoryNum' => $parentNum,
  ));
  
?>

<html>
  <body>
    <h1><?php echo htmlencode($parentCategory['name']) ?></h1>
    <ul>
      <?php foreach($categoryRecords as $category): ?>
        <?php echo $category['_listItemStart']; ?>
          <?php echo htmlencode($category['name']); ?>
        <?php echo $category['_listItemEnd']; ?>
      <?php endforeach; ?>
    </ul>
  </body>
</html>

Note that when using rootCategoryNum, you won't get the parent record back, so I've included an extra getRecords() call to get the parent category.

Please let me know if you have any questions.

All the best,
Chris

By zaba - March 3, 2014

Thanks Chris,

I'll be working on this this week, appreciate your response. :-)