Skip to:
Content
Pages
Categories
Search
Top
Bottom

If forum id=xyz echo different div for all topics of xyz


  • project_subdomain
    Participant

    @project_subdomain

    Hi!
    I’m trying to display different divs for all topics of specific forums.
    Wrong:

    <?php if ( is_post(xyz) ) : ?>
    <div>..</div>

    or

    <?php if ($forum_id=xyz) : ?> 
    <div>..</div>

    Suggest to need to use get_topic_id to get current topic ids?
    Would be very happy for any help with this!

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

  • Robkk
    Moderator

    @robkk

    I guess maybe try the conditional that is in this code. 13 is the topics forum id.

    function bbp_forum_thirteens() {
        $topic_id = bbp_get_topic_forum_id();
        
        if ( $topic_id == 13 ) {
            echo '<p>THIS is another test Thirteen</p>';
        }
    }    
        
    add_action( 'bbp_template_before_single_topic', 'bbp_forum_thirteens' );

    project_subdomain
    Participant

    @project_subdomain

    Thanks again, that’s it!
    This is how it works finally for several topics with different divs and a custom action hook:

    /*Different divs for all topics of specific forums*/
    
    function add_different_div() {
        
    $topic_id = bbp_get_topic_forum_id(); 
        if (( $topic_id == 123) or ( $topic_id == 456)){
    ?>
           <div> this is some custom div text </div>
    <?php
        }
    
    elseif ( $topic_id == 789){?>
    <div> this is some OTHER custom div text </div>
    <?php
    }}  
        
    add_action( 'different_div', 'add_different_div' );

    Custom action hook to add in the template file where the div shall be displayed:

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

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