1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Add more to the breadcrumb

Discussion in 'Styling and Customization Questions' started by Neil E., Sep 1, 2012.

  1. Neil E.

    Neil E. Active Member

    I need to add one more step to the breadcrumb trail. What needs to be done?

    Forums, click on any Node Title, breadcrumb shows Category Title.
    I want Category Title plus Node Title at this point.

    standard navigation code
    <xen:breadcrumb source="$nodeBreadCrumbs" />

    current modified navigation code (Node Title only shows up when viewing a thread)
    <xen:breadcrumb source="$nodeBreadCrumbs" />
    <xen:breadcrumb href="{xen:link full:threads, $thread}">{$thread.title}</xen:breadcrumb>

    The purpose is to show the node title sooner in the breadcrumb since I am not using a header title when viewing the thread list. Desired result:

    Viewing forum list, Breadcrumb = Forums, click on node
    Viewing thread list, Breadcrumb = Forums, Category Title, Node Title, click on topic title
    Viewing thread, Breadcrumb = Forums, Category Title, Node Title, Topic Title
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I have spent a lot of time with the breadcrumbs from developing the Nodes As Tabs addon. You need to modify the controller:


    In the actionIndex() function, remove the red code. That is a boolean to "include self" in the node crumbs. It defaults to true:

    		$viewParams = array(
    			'nodeList' => $this->_getNodeModel()->getNodeDataForListDisplay($forum, 0),
    			'forum' => $forum,
    			'nodeBreadCrumbs' => $ftpHelper->getNodeBreadCrumbs($forum, false),
    			'canPostThread' => $forumModel->canPostThreadInForum($forum),
    			'canSearch' => $visitor->canSearch(),
    			'inlineModOptions' => $inlineModOptions,
    			'threads' => $threads,
    			'stickyThreads' => $stickyThreads,
    			'ignoredNames' => $this->_getIgnoredContentUserNames($threads) + $this->_getIgnoredContentUserNames($stickyThreads),
    			'order' => $order,
    			'orderDirection' => $orderDirection,
    			'orderParams' => $orderParams,
    			'displayConditions' => $displayConditions,
    			'pageNavParams' => $pageNavParams,
    			'page' => $page,
    			'threadStartOffset' => ($page - 1) * $threadsPerPage + 1,
    			'threadEndOffset' => ($page - 1) * $threadsPerPage + count($threads) ,
    			'threadsPerPage' => $threadsPerPage,
    			'totalThreads' => $totalThreads,
    			'showPostedNotice' => $this->_input->filterSingle('posted', XenForo_Input::UINT)
    		return $this->responseView('XenForo_ViewPublic_Forum_View', 'forum_view', $viewParams);
    This can be made into an addon instead of a file edit if you want.
    Shelley likes this.
  3. Neil E.

    Neil E. Active Member

    Thanks, Jake.

    It's perfect.

    I notice that your code change matches the section 'thread' (which did have the complete breadcrumb).

            $viewParams = array(
                'thread' => array(
                    'discussion_open' => 1,
                    'prefix_id' => $forum['default_prefix_id'],
                'forum' => $forum,
                'nodeBreadCrumbs' => $ftpHelper->getNodeBreadCrumbs($forum),
                'prefixes' => $this->_getPrefixModel()->getUsablePrefixesInForums($forumId),
                'attachmentParams' => $attachmentParams,
                'watchState' => $this->_getThreadWatchModel()->getThreadWatchStateForVisitor(false),
                'captcha' => XenForo_Captcha_Abstract::createDefault(),
                'pollExtraArray' => $pollExtraArray,
                'canLockUnlockThread' => $this->_getForumModel()->canLockUnlockThreadInForum($forum),
                'canStickUnstickThread' => $this->_getForumModel()->canStickUnstickThreadInForum($forum),
                'attachmentConstraints' => $this->getModelFromCache('XenForo_Model_Attachment')->getAttachmentConstraints(),
            return $this->responseView('XenForo_ViewPublic_Thread_Create', 'thread_create', $viewParams);
    I'm so glad that you are able to help with XF.
    Would an addon be better for upgrading so the file is not overwritten?
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yeah that's the only reason. Otherwise you have to redo this file edit when you upgrade.
  5. Neil E.

    Neil E. Active Member

    The full breadcrumb is very handy. There are a few other places where I'd like to have the same functionality:

    A) When viewing Forums sub-tabs (Watched Threads, What's New)
    B) When viewing Members sub-tabs (Registered Members, Current Visitors, Recent Activity)
    C) When viewing Conversations (show Conversation Title)
    D) When viewing Account Pages (show page name)

    Can any of these be added to the breadcrumb?
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Those aren't nodes so it's different. You would start by identifying the content template:


    Then edit that template in your Admin CP. You need to add (or modify if it already exists) the xen:navigation block to define the breadcrumbs. Here is a code example from member_view:

    	<xen:breadcrumb href="{xen:link full:members, $user}">{$user.username}</xen:breadcrumb>
  7. Neil E.

    Neil E. Active Member

    That was fast! Thanks, I'll dig into it.
  8. Neil E.

    Neil E. Active Member

    I managed to spend some time on this and was able to add to the breadcrumb. The problem is that the last link does not function properly, it just goes back to the forum index. Here is what was added to the watch_threads template.

    Results in

    When inspected using Firebug

    In the last span class that is opened up a=" " so this looks to be the problem, but I don't know how to correct it.

    user "A"
    pass "a1234"
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You are doing it wrong. See the code example in my previous post. xen:breadcrumb has a href attribute for the hyperlink. And the content of xen:breadcrumb (between the two tags) is the text of the crumb.
  10. Neil E.

    Neil E. Active Member

    As usual Jake is correct. I had a space in my first template edit that messed things up. Then I went on a convoluted tangent with alternate breadcrumb syntax trying to make things work. A fresh look at it and all I needed was the following:
    So that has cleared up a few breadcrumb issues, however one instance has me baffled.
    I added the following to find_new_threads to add Recent Threads to the breadcrumb and it worked fine.
    Then I wanted to add What's New to the breadcrumb when looking at What's New. The problem is that What's New also uses the
    find_new_threads template as per this post http://xenforo.com/community/threads/whats-new-template.36639/
    Before setting up Recent Threads, I tried to get the breadcrumb working with What's New by itself. No luck with this at all.

    So how do I get What's New working and then control two different sets of breadcrumb content in one template?
  11. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    If it uses the same template there isn't much you can do. It's possible with an addon of course. You could define a breadcrumb variable in each controller and then use that as the source. Code example from thread_view:

    	<xen:breadcrumb source="$nodeBreadCrumbs" />
    Or you could specify two different content templates in the controllers.
  12. Neil E.

    Neil E. Active Member

    Thanks Jake. I was hoping a conditional might be possible in find_new_threads, something like IF Recent Threads use this path, ELSE use this path (for What's New).
  13. Marcel

    Marcel Active Member

    I'm just researching this topic now.
    This is exactly how I've done it, to include the thread title etc in the breadcrumb, as I too am not using the title part in the thread display.

    Just a quick point. I know I've already done this now, successfully, but your post says "Remove the word false, etc etc, It defaults to true"
    Don't you mean "Remove the word false, so then it will default to true". Just didn't sound right, reading it.

    Anyway...that aside, is there anyway to include the current prefix in this instead of just the thread title.
  14. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    That code change relates to node breadcrumbs. The thread title is not a node. Additional breadcrumbs such as thread titles are normally defined in the content template:


    See this template for a code example:

    Admin CP -> Appearance -> Templates -> member_view

    	<xen:breadcrumb href="{xen:link full:members, $user}">{$user.username}</xen:breadcrumb>
  15. Marcel

    Marcel Active Member

    Excellent, thanks Jake.

    I've managed to edit the thread_view template, changing the navigation to the following

       <xen:breadcrumb source="$nodeBreadCrumbs" />
       <xen:breadcrumb href="{xen:link full:threads, $thread}">{xen:helper threadPrefix, $thread, html, ''}&nbsp;{$thread.title}</xen:breadcrumb>
    This works fine. The prefix is there before the title.
    I tried to put a conditional in the middle of it to only show if the prefix existed but it didn't like that.
    However, how do I style the actual prefix part? Is it possible?

Share This Page