Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do I insert a bbPress single topic shortcode dynamically, using a template?

  • @erikalleman

    Participant

    I want to output bbPress single topic shortcodes with different IDs, through my single post template.

    On post with the title “A” shortcode [bbp-single-topic id=6041], on post with the title “B” shortcode [bbp-single-topic id=6042], etc…

    And the matching I need it via title strings, meaning that the topic with id 6041 would have the title “A”, and the topic with id 6042 would have the title “B”.

    How to achieve this, and what would be the dynamic query?

    I am using bbPress instead of comments, as they are post type, and I want to use this advantage.

Viewing 8 replies - 1 through 8 (of 8 total)
  • @robin-w

    Moderator

    so where are you placing this code ? eg in a page template?

    @erikalleman

    Participant

    Hi Robin,

    no, in my single post template.

    Originally I inserted them separately in my posts, but that of course comes with the lock-in effect, that is, if I want to change the layout of all of my posts, then i will have to edit them one by one – and this is unfeasible.

    @erikalleman

    Participant

    The idea is that I just simply want to display a topic with the same title as the post, under each post, as a comments section. Because they are post type, so I can achieve more with them in WordPress, as with comments.

    @robin-w

    Moderator

    untested, but try

    $title = get_the_title() ;
    $forums = bbp_get_forums_for_current_user() ;
    	foreach ($forums as $forum) {
    		if ($forum->post_title == $title) {
    			$forum_id= $forum->ID ;
    		}
    	}
    do_shortcode( '[bbp-single-topic id='.$forum_id.']' );	

    @erikalleman

    Participant

    Thank you!
    Should I insert the code above in my functions.php as it is, and use [bbp-single-topic id='.$forum_id.'] in my template?
    The fact that is not tested, can it break my site?

    @robin-w

    Moderator

    the code would go in your single post template – not having seen the template, I can’t say where !

    I was presuming that you were editing this template and Ftp’ing it to your site, in which case, yes it could break it, but you’d just keep a copy of the old template and FTP that back. If you have debugging switched on, then this will tell you where the error is to let you correct

    @erikalleman

    Participant

    I don’t use hand-coded, inline tempolates. I am using Templatera of WPBakery, and I am happy with it as it gives me a graphical overview of the structure, and they are easy to re-make or replace.

    In WPBakery, I have a javascript module, an html module, but there is no PHP module.

    But there is a text module which does accept shortcodes.
    What do you recommend in this scenario?

    @robin-w

    Moderator

    not used that, and as it is a paid product, I suggest you ask their support area

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