Breadcrumb Problem
4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 4, 2015 (RSS)
I am having a bit of a problem getting breadcrumbs to work properly on my site. I found some code in the forum that looked like it might work, so I tried it on a test page. I am down to one Warning, which I can't figure out how to solve. Can anyone help?
I get the following warning message
Warning: array_combine(): Both parameters should have an equal number of elements.... (it refers to line 2 in breadcrumbs.inc below)
Below is my menu.inc
<ul class="sf-menu">
<?php foreach ($menuRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected'] && !$categoryRecord['new_page']): ?>
<b><a href="<?php echo $categoryRecord['filename'] ?>" blank="_target"><?php echo $categoryRecord['name'] ?></a></b>
<?php else: ?>
<a href="<?php echo $categoryRecord['filename'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php endif; ?>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach; ?>
</ul>
<?php if (!$selectedMenu): ?>
No category is selected!<br/>
<?php endif ?>
Here is the breadcrumb.inc
<?php
$categoriesRecordsByNum = array_combine(array_pluck($categoryRecord, "num"), $categoryRecord);
$lineage = explode("\t", trim(preg_replace("/:/", "\t", $selectedMenu['lineage'])));
$parents = array();
foreach ($lineage as $parentCatNum) {
$parents[] = $categoriesRecordsByNum[$parentCatNum];
}
?>
<?php foreach($parents as $parent): ?>
<ul class="breadcrumblist">
<span>›</span>
<?php if ($parent === $selectedMenu): ?>
<li class="breadcrumbItem"> / <?php echo $parent['name'] ?></li>
<?php else: ?>
<li class="breadcrumbItem"> / <a href="<?php echo $parent['_link'] ?>"><?php echo $parent['name'] ?></a></li>
<?php endif ?>
</ul>
<?php endforeach ?>
northernpenguin
Northern Penguin Technologies
"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke
By Daryl - September 1, 2015
Hi northernpenguin,
Is the $categoryRecord in line 2 of breadcrumb.inc a multiple menu records or just a single record of a menu?
$categoriesRecordsByNum = array_combine(array_pluck($categoryRecord, "num"), $categoryRecord);
Base on your code, I'm assuming that $categoriesRecordsByNum should be a multiple menu records with the record num as the array keys. So can you try to replace the line 2 of breadcrumb.inc with:
$categoriesRecordsByNum = array_combine(array_pluck($menuRecords, "num"), $menuRecords);
Or with using array_groupBy function:
$categoriesRecordsByNum = array_groupBy($menuRecords, 'num');
Please let us know if that works.
Thanks,
PHP Programmer - interactivetools.com
Daryl: Yes, it is a multiple menu record. I tried both suggestions, and both only list the top level menu, Home.
northernpenguin
Northern Penguin Technologies
"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke
By Daryl - September 4, 2015
Hi Ragi,
Your code seems like it is for displaying only the top level menu or the selected parent menu.
Do you mind if I take a closer look by submitting a second level support request?
You can find the form here: https://www.interactivetools.com/support/email_support_form.php
Thanks,
PHP Programmer - interactivetools.com