Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbPress breadcrumb forum root link issue


  • stewmills
    Participant

    @stewmills

    Ok…I have scoured the bbPress forum and have tried several things and seem to be getting nowhere…and losing my mind at the same time.

    I have:
    WP 4.4.2
    bbPress 2.5.8
    BuddyPress 2.4.3
    Karma theme 3.0.3

    I set-up the forum using method 2, which is a page called “userforum” containing the shortcode [bbp-forum-index] and the forum displays just fine and as well shows my left sidebar which houses my login and other widgets. I want this sidebar on ALL forum pages and by creating a bbpress.php page I think I resolved the previous issue where I couldn’t see my sidebar on all pages. I should also note that my forum root slug is set to “forums”.

    So, the issue I have is that when I am on the main forum page (mysite.com/userforum) and drill down into a topic, the breadcrumb it creates is this: Forums > Forum Section > Topic. I can click on any of the breadcrumbs and get the full page with sidebar, but when I click on “Forums” in the breadcrumb it takes me to mysite.com/forums instead of mysite.com/userforum.

    Now you may tell me to change my forum root slug to “userforum” but when I do that and go back to my main forum page at mysite.com/userforum, my sidebar does not display on this page BUT the breadcrumb does not take me back to the main forum page mysite.com/userforum like I wanted.

    So, with that, what the heck am I missing? If someone can help I can get you into my actual forum page to peek under the hood. If there is simple code to add to my child functions.php file that will let me customize the URL or a simple setting I am missing somewhere?

    I have spent way too many hours trying to figure this out and I really need some help here.

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)

  • Robin W
    Moderator

    @robin-w

    the code you need is

    function change_root( $args = array() ) {
    
    		// Turn off breadcrumbs
    		if ( apply_filters( 'bbp_no_breadcrumb', is_front_page() ) )
    			return;
    
    		// Define variables
    		$front_id         = $root_id                                 = 0;
    		$ancestors        = $crumbs           = $tag_data            = array();
    		$pre_root_text    = $pre_front_text   = $pre_current_text    = '';
    		$pre_include_root = $pre_include_home = $pre_include_current = true;
    
    		/** Home Text *********************************************************/
    
    		// No custom home text
    		if ( empty( $args['home_text'] ) ) {
    
    			$front_id = get_option( 'page_on_front' );
    
    			// Set home text to page title
    			if ( !empty( $front_id ) ) {
    				$pre_front_text = get_the_title( $front_id );
    
    			// Default to 'Home'
    			} else {
    				$pre_front_text = __( 'Home', 'bbpress' );
    			}
    		}
    
    		/** Root Text *********************************************************/
    
    		// No custom root text
    		if ( empty( $args['root_text'] ) ) {
    			$page = bbp_get_page_by_path( bbp_get_root_slug() );
    			if ( !empty( $page ) ) {
    				$root_id = $page->ID;
    			}
    			$pre_root_text = bbp_get_forum_archive_title();
    		}
    
    		/** Includes **********************************************************/
    
    		// Root slug is also the front page
    		if ( !empty( $front_id ) && ( $front_id === $root_id ) ) {
    			$pre_include_root = false;
    		}
    
    		// Don't show root if viewing forum archive
    		if ( bbp_is_forum_archive() ) {
    			$pre_include_root = false;
    		}
    
    		// Don't show root if viewing page in place of forum archive
    		if ( !empty( $root_id ) && ( ( is_single() || is_page() ) && ( $root_id === get_the_ID() ) ) ) {
    			$pre_include_root = false;
    		}
    
    		/** Current Text ******************************************************/
    
    		// Search page
    		if ( bbp_is_search() ) {
    			$pre_current_text = bbp_get_search_title();
    
    		// Forum archive
    		} elseif ( bbp_is_forum_archive() ) {
    			$pre_current_text = bbp_get_forum_archive_title();
    
    		// Topic archive
    		} elseif ( bbp_is_topic_archive() ) {
    			$pre_current_text = bbp_get_topic_archive_title();
    
    		// View
    		} elseif ( bbp_is_single_view() ) {
    			$pre_current_text = bbp_get_view_title();
    
    		// Single Forum
    		} elseif ( bbp_is_single_forum() ) {
    			$pre_current_text = bbp_get_forum_title();
    
    		// Single Topic
    		} elseif ( bbp_is_single_topic() ) {
    			$pre_current_text = bbp_get_topic_title();
    
    		// Single Topic
    		} elseif ( bbp_is_single_reply() ) {
    			$pre_current_text = bbp_get_reply_title();
    
    		// Topic Tag (or theme compat topic tag)
    		} elseif ( bbp_is_topic_tag() || ( get_query_var( 'bbp_topic_tag' ) && !bbp_is_topic_tag_edit() ) ) {
    
    			// Always include the tag name
    			$tag_data[] = bbp_get_topic_tag_name();
    
    			// If capable, include a link to edit the tag
    			if ( current_user_can( 'manage_topic_tags' ) ) {
    				$tag_data[] = '<a href="' . esc_url( bbp_get_topic_tag_edit_link() ) . '" class="bbp-edit-topic-tag-link">' . esc_html__( '(Edit)', 'bbpress' ) . '</a>';
    			}
    
    			// Implode the results of the tag data
    			$pre_current_text = sprintf( __( 'Topic Tag: %s', 'bbpress' ), implode( ' ', $tag_data ) );
    
    		// Edit Topic Tag
    		} elseif ( bbp_is_topic_tag_edit() ) {
    			$pre_current_text = __( 'Edit', 'bbpress' );
    
    		// Single
    		} else {
    			$pre_current_text = get_the_title();
    		}
    
    		/** Parse Args ********************************************************/
    
    		// Parse args
    		$r = bbp_parse_args( $args, array(
    
    			// HTML
    			'before'          => '<div class="bbp-breadcrumb"><p>',
    			'after'           => '</p></div>',
    
    			// Separator
    			'sep'             => is_rtl() ? __( '&lsaquo;', 'bbpress' ) : __( '&rsaquo;', 'bbpress' ),
    			'pad_sep'         => 1,
    			'sep_before'      => '<span class="bbp-breadcrumb-sep">',
    			'sep_after'       => '</span>',
    
    			// Crumbs
    			'crumb_before'    => '',
    			'crumb_after'     => '',
    
    			// Home
    			'include_home'    => $pre_include_home,
    			'home_text'       => $pre_front_text,
    
    			// Forum root
    			'include_root'    => $pre_include_root,
    			'root_text'       => $pre_root_text,
    
    			// Current
    			'include_current' => $pre_include_current,
    			'current_text'    => $pre_current_text,
    			'current_before'  => '<span class="bbp-breadcrumb-current">',
    			'current_after'   => '</span>',
    		), 'get_breadcrumb' );
    
    		/** Ancestors *********************************************************/
    
    		// Get post ancestors
    		if ( is_singular() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit() ) {
    			$ancestors = array_reverse( (array) get_post_ancestors( get_the_ID() ) );
    		}
    
    		// Do we want to include a link to home?
    		if ( !empty( $r['include_home'] ) || empty( $r['home_text'] ) ) {
    			$crumbs[] = '<a href="' . trailingslashit( home_url() ) . '" class="bbp-breadcrumb-home">' . $r['home_text'] . '</a>';
    		}
    
    		// Do we want to include a link to the forum root?
    		if ( !empty( $r['include_root'] ) || empty( $r['root_text'] ) ) {
    
    			// Page exists at root slug path, so use its permalink
    			$page = bbp_get_page_by_path( bbp_get_root_slug() );
    			if ( !empty( $page ) ) {
    				$root_url = get_permalink( $page->ID );
    
    			// Use the root slug
    			} else {
    				$root_url = get_post_type_archive_link( bbp_get_forum_post_type() );
    			}
    
    			// Add the breadcrumb
    			//$crumbs[] = '<a href="' . esc_url( $root_url ) . '" class="bbp-breadcrumb-root">' . $r['root_text'] . '</a>';
    		$crumbs[] = '<a href="/forums/">Forums</a>';
    
    		}
    
    		// Ancestors exist
    		if ( !empty( $ancestors ) ) {
    
    			// Loop through parents
    			foreach ( (array) $ancestors as $parent_id ) {
    
    				// Parents
    				$parent = get_post( $parent_id );
    
    				// Skip parent if empty or error
    				if ( empty( $parent ) || is_wp_error( $parent ) )
    					continue;
    
    				// Switch through post_type to ensure correct filters are applied
    				switch ( $parent->post_type ) {
    
    					// Forum
    					case bbp_get_forum_post_type() :
    						$crumbs[] = '<a href="' . esc_url( bbp_get_forum_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title( $parent->ID ) . '</a>';
    						break;
    
    					// Topic
    					case bbp_get_topic_post_type() :
    						$crumbs[] = '<a href="' . esc_url( bbp_get_topic_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title( $parent->ID ) . '</a>';
    						break;
    
    					// Reply (Note: not in most themes)
    					case bbp_get_reply_post_type() :
    						$crumbs[] = '<a href="' . esc_url( bbp_get_reply_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title( $parent->ID ) . '</a>';
    						break;
    
    					// WordPress Post/Page/Other
    					default :
    						$crumbs[] = '<a href="' . esc_url( get_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-item">' . get_the_title( $parent->ID ) . '</a>';
    						break;
    				}
    			}
    
    		// Edit topic tag
    		} elseif ( bbp_is_topic_tag_edit() ) {
    			$crumbs[] = '<a href="' . esc_url( get_term_link( bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id() ) ) . '" class="bbp-breadcrumb-topic-tag">' . sprintf( __( 'Topic Tag: %s', 'bbpress' ), bbp_get_topic_tag_name() ) . '</a>';
    
    		// Search
    		} elseif ( bbp_is_search() && bbp_get_search_terms() ) {
    			$crumbs[] = '<a href="' . esc_url( bbp_get_search_url() ) . '" class="bbp-breadcrumb-search">' . esc_html__( 'Search', 'bbpress' ) . '</a>';
    		}
    
    		/** Current ***********************************************************/
    
    		// Add current page to breadcrumb
    		if ( !empty( $r['include_current'] ) || empty( $r['current_text'] ) ) {
    			$crumbs[] = $r['current_before'] . $r['current_text'] . $r['current_after'];
    		}
    
    		/** Separator *********************************************************/
    
    		// Wrap the separator in before/after before padding and filter
    		if ( ! empty( $r['sep'] ) ) {
    			$sep = $r['sep_before'] . $r['sep'] . $r['sep_after'];
    		}
    
    		// Pad the separator
    		if ( !empty( $r['pad_sep'] ) ) {
    			if ( function_exists( 'mb_strlen' ) ) {
    				$sep = str_pad( $sep, mb_strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH );
    			} else {
    				$sep = str_pad( $sep, strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH );
    			}
    		}
    
    		/** Finish Up *********************************************************/
    
    		// Filter the separator and breadcrumb
    		$sep    = apply_filters( 'bbp_breadcrumb_separator', $sep    );
    		$crumbs = apply_filters( 'bbp_breadcrumbs',          $crumbs );
    
    		// Build the trail
    		$trail  = !empty( $crumbs ) ? ( $r['before'] . $r['crumb_before'] . implode( $sep . $r['crumb_after'] . $r['crumb_before'] , $crumbs ) . $r['crumb_after'] . $r['after'] ) : '';
    
    		return apply_filters( 'change_root', $trail, $crumbs, $r );
    	}
    
    add_filter ('bbp_get_breadcrumb', 'change_root') ;

    pulled from a thread I did long ago

    I don’t know how code aware you are to change this to what you want, so come back and let me know – it would take me a while to work out what to change, and I really don’t want to do this if you are capable !


    stewmills
    Participant

    @stewmills

    Thanks Robin! At my present state of bbpress experience this may be a bit over my head. I made a list of the forum pages in my sidebar as well as a link to Forum Home and will just use that as the way back to the forum main page. Maybe as I get more experience I will come back and revisit this later.


    wautersandreas
    Participant

    @wautersandreas

    Hi, i have the same exact problem.
    I don’t really know why everybody isn’t tagging this as an issue. As far as i can see, it’s just nog a logical way to do it.

    – on the one hand, a forum index is created by default, but cyou can’t use it on it’s own if you want to start customizing things.
    – So you need to make a page and put the index in there.
    – On the other hand, you can’t easily specify what your page for the root is, so there is no way to let the breadcrumbs be redirected to the index page.

    – Are there other options? because the enormous bit of code to fix it is a bit too complex for me.


    stewmills
    Participant

    @stewmills

    To the best of my memory, I added the below to my themes’s child functions.php file to disable the “forums” breadcrumb that links back to the “forums” page that does not include the sidebar. NOTE that I am not a developer and got the below from this forum somewhere last year so use at your discretion. If you crash your site, I accept no responsibility!!
    +++++++++++++++++++++++++++++++++++++++++

    function rkk_custom_bbpbreadcrumbs() {
    // Remove Forum root from bbPress breadcrumbs
    $args[‘include_root’] = false;
    return $args;
    }

    add_filter(‘bbp_before_get_breadcrumb_parse_args’, ‘rkk_custom_bbpbreadcrumbs’);


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    If you create a page with the same slug as your forum index, you can use either the [bbp-forum-index] or [bbp-topic-index] shortcode in your page content to output the list you desire.

    bbPress won’t complain, and you’ll be able to customize the page title and content if you desire.

    It’s not exactly a hidden trick, but it’s what we use here on bbPress.org and seems to work OK. If that approach is creating a broken breadcrumb, that’s definitely a bug.


    dropshot
    Participant

    @dropshot

    @JohnJamesJacoby

    The problem is if you create a page with the same slug as your forum index and insert the forum index shortcode, this page will just be a page that happens to contain bbpress content. It isn’t a real bbpress page.

    If you would like your index page (mysite.com) as your forum index how can you make that a real forum page? NOT just a page that contains bbpress content.

    You can’t set your forum root index to nothing cause this will make default value (forums) to reappear. Of course you can 301 redirect /forums to index page. But as mentioned, this will display a page with forum content. NOT a real forum page.

    Appreciate any kind of suggestions.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.