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

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: [drewh01] Creating a dynamic dropdown menu

I have Same Problem

I wrote this recursive Function
you can Use Your Css Or Set Custom Tags And attr ...

<ol >
<?php

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

//GetChild Recursive Function
function getchild($recnum,$categoryRecords)
{
$childs=0;
foreach ($categoryRecords as $child):
if($recnum == $child['parentNum'])
$childs++;
endforeach;
if($childs>0)
{
$childs = 0;
echo "<ol>";
foreach ($categoryRecords as $child):
if($recnum == $child['parentNum'])
{
echo "<li>".$child['name']."";
getchild($child['num'],$categoryRecords);
}
else
{
echo"</li>";
}
endforeach;
echo "</ol>";
}

}
// End Function
foreach ($categoryRecords as $categoryRecord):
if($categoryRecord['parentNum'] == 0)
{
echo "<li>".$categoryRecord['name']."";
getchild($categoryRecord['num'],$categoryRecords);

}
endforeach;
?>
</ol>


This is my Email : smaeily@gmail.com

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 ?!