Creating a dynamic dropdown menu

31 posts by 7 authors in: Forums > CMS Builder
Last Post: October 12, 2012   (RSS)

By drewh01 - May 8, 2012

Thanks, for example, what would I remove in this code:

<ul>
<?php foreach ($allPages as $page): ?>

<?php $link = $page['url'] ? $page['url'] : $page['_link']; ?>

<?php echo $page['_listItemStart'] ?>

<?php if ($page['_isSelected']): ?>

<a href="<?php echo $link; ?>"><?php echo $page['title'] ?></a>

<?php else: ?>

<li>
<a href="<?php echo $link; ?>">
<?php echo $page['title'] ?>
</a>

<?php endif; ?>
<?php echo $page['_listItemEnd'] ?>

<?php endforeach; ?>
</ul>


Currently I get a lot of errors like this one: Notice: Undefined index: parentNum in /home/hummingb/public_html/cmsAdmin/lib/viewer_functions.php on line 806 Notice: Undefined index: parentNum in /home/hummingb/public_html/cmsAdmin/lib/viewer_functions.php on line 807

Re: [drewh01] Creating a dynamic dropdown menu

By Jason - May 8, 2012

Hi,

The code in the previous post:

<?php foreach ($allPages as $page): ?>

<?php $link = $page['url'] ? $page['url'] : $page['_link']; ?>

<a href="<?php echo $link; ?>"> <?php echo $page['name'] ?> </a>


<?php endforeach; ?>


should work. Make sure that you are using getRecords() instead of getCategories().

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By drewh01 - May 8, 2012

Here is the page I am working with.
Attachments:

festival2.php 9K

Re: [drewh01] Creating a dynamic dropdown menu

By Jason - May 8, 2012

Hi,

I took a look at your file. First you'll need to use getRecords() instead of getCategories(). This is what's causing your first set of errors. After that, you'll need to change your foreach loop to match what was in the previous post.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By drewh01 - May 8, 2012

Still unable to get it to work...
Attachments:

festival3.php 9K

Re: [drewh01] Creating a dynamic dropdown menu

By Jason - May 9, 2012

Hi,

First, you need to change your getRecords query, as the function doesn't use the "categoryFormat" option.

Try this:

list($allPages, $selectedPage) = getRecords(array(
'tableName' => 'festival_pages',
'allowSearch' => false,
));


Then in your loop, you still have an extra "else" block and some left over code.

Try this:

<ul>
<?php foreach ($allPages as $page): ?>

<?php $link = $page['url'] ? $page['url'] : $page['_link']; ?>

<li><a href="<?php echo $link; ?>"> <?php echo $page['title'] ?> </a> </li>


<?php endforeach; ?>
</ul>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By drewh01 - May 9, 2012

ok, that makes sense - thanks!

Re: [Esmaeili] Creating a dynamic dropdown menu

Hi,

CMS Builder has built in functions that make creating nested comments fairly straight forward. You could try something like this:

<?php

list($support_categoriesIndexRecords, $categoriesMeta) = getCategories(array(
'tableName' => 'main_menu', // REQUIRED
'rootCategoryNum' => '0'
));
?>


<?php echo '<ul>';
foreach($support_categoriesIndexRecords as $key => $row ){
if($row['depth'] == '0' ){
echo $row['_listItemStart'].$row['name'].$row['_listItemEnd'];
}
elseif($row['_isSelectedBranch']){
echo $row['_listItemStart'].$row['name'].$row['_listItemEnd'];
}
}
echo '</ul>';

Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Creating a dynamic dropdown menu

How Can set Custom Tags to _listItemStart ?!