1

I've got this bit of code that works well for my Joomla setup

However, due to the way my main menu is set up, the first item in every page we have breadcrumbs enabled is always "Products" grayed out -( can't click) - this is due to "Products" being a "Menu Heading"

What can I do with the following so the first item is always the same link ( ie Product Category )

 ?>
<ul class="uk-breadcrumb"><?php

    if (!$params->get('showLast', 1)) array_pop($list);

    for ($i = 0; $i < $count; $i ++) {

        if ($i == 1 && !empty($list[$i]->link) && !empty($list[$i - 1]->link) && $list[$i]->link == $list[$i - 1]->link)
        {
            continue;
        }

        // clean subtitle from breadcrumb
        if ($pos = strpos($list[$i]->name, '||')) {
            $name = trim(substr($list[$i]->name, 0, $pos));
        } else {
            $name = $list[$i]->name;

        }

        // mark-up last item as strong
        if ($i < $count-1) {
            if (!empty($list[$i]->link)) {
                echo '<li><a href="'.$list[$i]->link.'">'.$name.'</a></li>';
            } else {
                echo '<li><span>'.$name.'</span></li>';
            }
        } else {
            echo '<li class="uk-active"><span>'.$name.'</span></li>';
        }

    }

?></ul>
<?php endif; ?>

I tried adding the below to no avail

echo '<li><span><a href="https://www.example.com/products/product-category">Product Category</a></span></li>';

Essentially, I'm just trying change the Menu Heading in the breadcrumb to a hyperlink, I understand this may not be the best way (hard coding it in) but it will work for my situation.

2
  • Do we need to see your $list? "To no avail" -- you mean you write your static <li> line before your loop and then what happens? Is it not printed? It is printed gray? Is this a css issue? Did you inspect the element to see what styles are being applied, then trace the style back to a css declaration that you might try to adjust?
    – mickmackusa
    Jan 30 at 21:20
  • You wouldn't need to , at least I dont think so. Essentially I'm just trying to change the text from "Products" to a hyperlink of my choosing.
    – Nick
    Jan 30 at 21:23

1 Answer 1

0

I was able to figure this out with some trial and error.

I changed one line:

echo '<li><span>'.$name.'</span></li>';

to:

echo '<li><span><a href="https://www.example.com/products/category">Category</a></span></li>';

Here is the whole finished snippet:

<ul class="uk-breadcrumb">
    <?php
    if (!$params->get('showLast', 1)) {
        array_pop($list);
    }

    for ($i = 0; $i < $count; $i++) {

        if ($i == 1
            && !empty($list[$i]->link)
            && !empty($list[$i - 1]->link)
            && $list[$i]->link == $list[$i - 1]->link
        ) {
            continue;
        }

        // clean subtitle from breadcrumb
        if ($pos = strpos($list[$i]->name, '||')) {
            $name = trim(substr($list[$i]->name, 0, $pos));
        } else {
            $name = $list[$i]->name;
        }

        // mark-up last item as strong
        if ($i < $count - 1) {
            if (!empty($list[$i]->link)) {
                echo '<li><a href="' . $list[$i]->link . '">' . $name . '</a></li>';
            } else {
                echo '<li><span><a href="https://www.example.com/products/category">Category</a></span></li>';
            }
        } else {
            echo '<li class="uk-active"><span>' . $name . '</span></li>';
        }
    }
    ?>
</ul>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.