Skip to:
Content
Pages
Categories
Search
Top
Bottom

Changing the first item on a topic list


  • jd-fb
    Participant

    @jd-fb

    I was wondering if there were a way to not have a topic’s content appear in its own box at the top of the reply list. Ditto for the forum content (in other words, the HTML that output using bbp_topic_content() and bbp_forum_content() respectively).

    The built-in bbPress styling shows the topic and forum content in a box that has the same (or very simiar) styling as replies. In my case, I’d like to remove the box so that the content appears as though it’s the lead-in text of a page (with H2s, H3s and so forth) with the replies + reply form below.

    Can someone point me in the right direction?

    Idea / potential solution 1)
    I found that I can do this:

    add_action ('bbp_template_before_single_topic', 'show_text');
    function show_text() {
    	ob_start();	
    	echo '<div class="my_class">';
    	add_action ('bbp_get_topic_content', 'do_shortcode'); // added b/c the content may have shortcodes
    	bbp_topic_content();
    	echo '</div>';   
    	$output = ob_get_clean();   
    	echo $output;
    }

    But this results in the topic content appearing in both the “top” of the page (as I’d prefer) and in its box listed with the replies (which I’d like to remove).

    Idea / potential solution 2)
    I’m guessing there’s something I can do with a template. If so, can someone direct me to how my plug-in can override bbPress’s template? I haven’t done a lot of template work.

    Troubleshooting
    – All themes have this “extra box” issue.
    – Using WP 4.9.8
    – Using bbPress 2.5.14-6684
    – I’m working on a local site, so I can’t provide a link

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

  • jd-fb
    Participant

    @jd-fb

    I just noticed that this website, bbpress.org, does something similar to what I’m looking for. (Except, I’d remove the avatar and date.)

    So, how does that work? I noticed that this site’s theme is called BB’s Parent, but that doesn’t seem to be available to the public (so I can’t check its code 🙁 )


    Robin W
    Moderator

    @robin-w


    jd-fb
    Participant

    @jd-fb

    Thanks for the reply… but I think looking at the theme files only confused me more. (Sorry!)

    I’ve taken a look at templates/loop-replies.php that’s built-into the plugin, which (if I understand correctly) is what is used when a user is viewing a topic’s page (in other words http://domain.com/forum/topic/awesomness/). I’m kind of confused as to how it works – near the bottom of this template, it calls another template using bbp_get_template_part( 'loop', 'single-reply' ); – and it does this whether it’s the topic’s content or a reply to the topic.

    So, I’m uncertain if I need to modify the WP_Query (or where), or if I should modify the template.


    Robin W
    Moderator

    @robin-w

    I’m out this weekend, but I’ll read this early next week


    Robin W
    Moderator

    @robin-w

    ok, so concentrating on a topic and it’s reply list and ignoring forums, you are saying that you would like

    from clicking a topic in the forum list (a list of topics in the forum) you are taken to a page which displays

    • the topic name
    • some content/info but styled and controlled by you
    • the replies as per normal
    • the reply form

    If so I suspect you need to do two things

    1. use this piece of code in your functions file

    bbp_show_lead_topic

    2. amend content-single-topic-lead.php in your child theme’s bbpress directory.

    by

    create a directory on your theme called ‘bbpress’
    ie wp-content/themes/%your-theme-name%/bbpress

    where %your-theme-name% is the name of your theme

    find
    wp-content/plugins/bbpress/templates/default/bbpress/content-single-topic-lead.php
    Make a copy of this file, and put in in the directory called bbpress that you created above, so you end up with
    wp-content/themes/%your-theme-name%/bbpress/content-single-topic-lead.phpbbPress will now use this template instead of the original and you can amend this

    I have no idea how technical you are and whether that gives you enough to go ahead and fix, or if you need further help – let me know


    jd-fb
    Participant

    @jd-fb

    Thanks Robin. I previously played with bbp_show_lead_topic, and I couldn’t get it to work (which is why I posted my question above.) I guess I was missing step 2, which is the template.

    Question: Do the steps you describe change if I’m developing a plugin, instead of a theme? If I’m correct, the following code should help me (correct?)

    correct way to override bbpress templates


    Robin W
    Moderator

    @robin-w

    the function (1) can sit in your plugin

    the template (2) can also be in your plugin, but yes, you’ll need some code to do this

    in my style pack plugin I have a directory and sub directory called

    templates/templates1 and in this I have a bbpress templates I have amended eg

    wp-content/plugins/bbp-style-pack/templates/template1/loop-forums.php

    then in my plugin code I have (you’ll need to amend BSP_PLUGIN_DIR to a suitable name for your plugin

    if(!defined('BSP_PLUGIN_DIR'))
    	define('BSP_PLUGIN_DIR', dirname(__FILE__));
    
    add_action( 'bbp_register_theme_packages', 'bsp_register_plugin_template1' );
    
    function bsp_register_plugin_template1() {
    	bbp_register_template_stack( 'bsp_get_template1_path', 12 );
    }
    
    function bsp_get_template1_path() {
    	return BSP_PLUGIN_DIR . '/templates/templates1';
    }

    This loads all templates in that directory and registers them with bbpress

    come back if that doesn’t work for you with your code


    jd-fb
    Participant

    @jd-fb

    Thanks again, Robin!
    I’ve successfully used the code above to modify the templates. Woo!

    However, one question / comment:
    The code you’ve provided for bbp_show_lead_topic doesn’t seem to do anything for me.
    I’ve tried:

    function custom_bbp_show_lead_topic( $show_lead ) {
      $show_lead[] = 'false'; // The code as shown on https://codex.bbpress.org/bbp_show_lead_topic/
      $show_lead[] = false; // No quotation marks around 'false'
      $show_lead = false;   // no array [] used on $show_lead, no quotation;
      $show_lead = 'false'  // no array, with quotation
      return $show_lead;
    }

    And none of these seemed to change how the lead topic was displayed.
    But, I’ve figured out the templates and I’m getting the results I was hoping for.

    Thanks again.


    Robin W
    Moderator

    @robin-w

    the default is false, so it would do nothing – you should be using

    $show_lead[] = 'true';

    then it will use the template it talks about and you can style it

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