3

How can I get a breadcrumb path by providing $nid?

Example

$nid = 116;
$breadcrumb = breadcrumb_get_crumb($nid);

I have a node type that is always associated with another node, and I want to use that node's breadcrumb trail for this node too.

3 Answers 3

2

You could use Crumbs module. Now, if you say these nodes are "associated", I wonder how exactly? With an Entity reference field? Or just that you know the parent? Is this for all nodes of this type, or just for this specific one? Are these nodes somewhere in a menu?

If you can arrange either of the criteria above, you can use existing Crumbs plugins. Otherwise, you could do a custom module..

0

sounds to me that you could use the Custom Breadcrumbs module, just set those node types custom breadcrumbs to what you want.

0

I just wrote a function to retrieve this information. It loops through the menu structure several times and builds a array with the needed info.

function getBreadcrumbs($menu)
{

    $menu = @menu_load_links($menu);
    $breadcrumbs = array();
    $parentSearch = -1;

    // check 10 levels back from the current page, back to the highest page
    for ($i = 0; $i <= 10; $i++) {
        // stop when the item with no parent is found
        if ($parentSearch === 0) {
            continue;
        }
        // loop the menu for this level check
        foreach($menu as $item) {
            $link = url($item['link_path']);
            if ($link === url(current_path()) && $parentSearch === -1) {
                $breadcrumbs[] = array('title' => $item['link_title'], 'url' => $link, 'current' => true, 'mlid' => $item['mlid']);
                $parentSearch = (int) $item['plid'];
            } else if ($parentSearch !== -1 && (int) $item['mlid'] === $parentSearch) {
                $breadcrumbs[] = array('title' => $item['link_title'], 'url' => $link, 'current' => false, 'mlid' => $item['mlid']);
                $parentSearch = (int) $item['plid'];
            }
        }
    }

    return array_reverse($breadcrumbs);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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