Skip to:
Content
Pages
Categories
Search
Top
Bottom

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


  • erikalleman
    Participant

    @erikalleman

    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

    @robin-w

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


    erikalleman
    Participant

    @erikalleman

    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

    @erikalleman

    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

    @robin-w

    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

    @erikalleman

    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

    @robin-w

    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

    @erikalleman

    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

    @robin-w

    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