Combo code Hierarchical List

5 posts by 2 authors in: Forums > CMS Builder
Last Post: April 29, 2013   (RSS)

By esupport - April 26, 2013

Hi,

I create a "Category Menu" section and generat a combo code.

Here is the left site of the Combo code

<?php foreach ($ec_km_listRecords as $listRecord): ?>
<?php $isSelected = ($listRecord['num'] == $detailRecord['num']); ?>
<?php if ($isSelected) { print "<b>"; } ?>
<a href="<?php echo htmlencode($listRecord['_link']) ?>"><?php echo htmlencode($listRecord['name']) ?></a><br/>
<?php if ($isSelected) { print "</b>"; } ?>
<?php endforeach ?>

<?php if (!$ec_km_listRecords): ?>
No records were found!<br/><br/>
<?php endif ?>

How can I create it as a Hierarchical List item?   

Thanks!

Jac

-Jax H.

Hi Jac,

Here is an example of how you can create a hierarchical menu system using a category section:

<?php
  // load records from 'animal_category'
  list($categories, $categoryMeta) = getCategories(array(
    'tableName'   => 'category_menu_section_name',
  ));
?>
<ul>
  <?php foreach($categories as $category): ?>
    <?php $isSelected = ($category['num'] == @$detailRecord['num']); ?>
    <?php echo $category['_listItemStart']; ?>
      <?php if ($isSelected) { echo "<b>"; } ?>
        <?php echo $category['name']; ?>
      <?php if ($isSelected) { echo "</b>"; } ?>
    <?php echo $category['_listItemEnd']; ?>
  <?php endforeach; ?>
</ul>

This is example code, so you'll have to make a few changes to get it working, specifically you'll have change category_menu_section_name to the name of your category menu section.

So I've used the getCategories function to retrieve the category menu items. This function will automatically generate list item start and end tags using the meta field _listItemStart and _listItemEnd

I've also integrated the $isSelected variable, so the current menu item should be highlighted in bold.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By esupport - April 26, 2013

Hi Gerg

sorry again!

I have setted correct List Page Url & Detail Page Url on my cmsAdmin Viewer Urls.

I found I couldn't get the detail page for my combo code.

The attachment is my code.

Please kindly help.

Thanks!!

Jac

-Jax H.
Attachments:

categorylist_008.php 3K

Morning Jac,

The issue was that nothing was set to the $selectedCategory value in page. I've changed your system so that the detailed record for the page is retrieved using a getRecords function:

  // load record from 'blog'
  list($categoryDetail, $blogMetaData) = getRecords(array(
    'tableName'   => 'category',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $categoryDetail = @$categoryDetail[0]; // get first record
  if (!$categoryDetail) { dieWith404("Record not found!"); } // show error message if no record found

Then I've replaced the selectedCategory data with categoryDetail:

      <td valign="top">
        <?php if (!$selectedCategory): ?>
        No record selected
        <?php endif; ?>
        <?php if ($categoryDetail): ?>
        <h3><?php echo $categoryDetail['name'] ?></h3>
        <?php echo $categoryDetail['content'] ?>
        <?php endif; ?></td>

I've attached my updated code to this post.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com