Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Breadcrumbs (what URL to use for forum)


  • Michael
    Participant

    @michaelgoulden

    Hello,

    I’ve been having issues with breadcrumbs, and gone through various mechanisms to get them working efficiently with no joy.

    My needs are simple, so looking to create a simple button in my single topic template to go back to the forum the topic is a part of.

    Can anyone suggest the best URL and code to use?

    / Background:

    – I have created multiple single forums
    – I have then created multiple WP pages, and used the single forum shortcode to embed the forum in the page
    – I’d like to include one button at the top of the topic, that simply takes the user back to the relevant page that is hosting that particular forum (not the bbP forum page)

    / Location of code:

    I am guessing (non-coder) that the best location for this code would be as follows (within content-single-topic.php). Is this correct? (see code below)


    <?php

    /**
    * Single Topic Content Part
    *
    * @package bbPress
    * @subpackage Theme
    */

    ?>

    /* BUTTON HERE */

    <div id="bbpress-forums">

    <?php bbp_breadcrumb(); ?>

    <?php do_action( 'bbp_template_before_single_topic' ); ?>

    Cheers,

    Michael

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

  • Robin W
    Moderator

    @robin-w

    I’d suggest you do this as follows:

    there is a ‘hook’ that you show above called ‘<?php do_action( ‘bbp_template_before_single_topic’ ); ?>’

    This tells bbpress to do any action that is added at that point.

    so adding a hook will mean that the function is called at that point.

    The following code should go in your child theme functions file, or use the code snippets plugin

    Code Snippets

    add_action ( 'bbp_template_before_single_topic' , 'rew_back' ); 
    
    function rew_back () {
    	$text = 'click to go back' ;
    	if (bbp_get_topic_forum_id() == '25') $href = home_url( '/forum/domestics/' ) ;
    	if (bbp_get_topic_forum_id() == '33') $href = home_url( '/forum/commercial/' ) ;
    		//where to go if page not there
    	else $href = home_url( '/login/' ) ;
    	echo '<a class="button" href ="'.$href.'">'.$text.'</a>' ;
    }

    so each forum will need a line.


    Michael
    Participant

    @michaelgoulden

    Hi Robin,

    Thank you so much for taking the time – this was a lot simpler than I expected! And easy to maintain.

    Cheers,

    Michael


    Robin W
    Moderator

    @robin-w

    great – glad you are fixed

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