Skip to:
Content
Pages
Categories
Search
Top
Bottom

Remove in first forum only

  • @demonboy

    Participant

    In single-loop-forum.php I want to style my first forum differently to the rest by removing the voices/topics/freshness columns. As it happens this forum is only visible to non-logged in users by using this code:

    .logged-in #bbp-forum-40250 {
    	display: none;
    }

    I found this code here:

    /*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' );

    … but creating a function seems overkill. I think I just need an if() statement that says ‘if this forum ID then style it this way; else…’.

    Any pointers?

    Thanks.

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

    Moderator

    given the speed of most servers, I doubt that you would notice any time delay in processing the code in is a few lines of many thousand that get processed on each page load and one DB call.

    best solution would be to time with and without and see if you can spot anything – but run it many times to get an average

    @demonboy

    Participant

    Hi Robin. Yes, you have a good point. My functions.php file is filling up with these and it’s making no difference on load times. TBH I’m not sure how I would edit the above function to pull the correct forum ID as this one seems to deal with topic ID instead. Does it treat topic ID and forum ID as the same? As in, can I just change the ID number within this part:

    if (( $topic_id == 123)

    @robin-w

    Moderator

    you need to pick up the forum id

    so

    $forum_id = bbp_get_forum_id(); 
        if (( $forum_id == 123) or ( $forum_id == 456)){

    etc…

    and then you would add the

    Custom action hook to add in the template file where the div shall be displayed:
    <?php do_action( 'different_div' ); ?>

    in the appropriate forum template

    @demonboy

    Participant

    Hi Robin,

    Using your prompt I hacked something that removes the action altogether and just uses the if statement. On the loop-single-forum.php file I started with this:

    <?php $forum_id = bbp_get_forum_id(); 
        if (( $forum_id == 40250) ){
    ?>
         <li class="bbp-forum-info-40250">  
    <?php
        }
    
    else {?>
    	<li class="bbp-forum-info">
    <?php
    }?>

    where I set the CSS selector ‘bbp-forum-info-40250’ width to 100%. At the end of the template I then added this:

    <?php $forum_id = bbp_get_forum_id(); 
        if (( $forum_id == 40250) ){
    ?>
           
    <?php
        }
    
    else {?>	
    	<li class="bbp-forum-topic-count"><?php bbp_forum_topic_count(); ?></li>
            rest of the normal template follows
    	</li>
    <?php
    }?>

    where nothing appears for forum id 40250 and the rest of the template displays as normal for all other forums. So now my first forum description is 100% width without topic counts/views/freshness, whilst the rest of the forums display as normal.

    If interested you can see the result here.

    @robin-w

    Moderator

    great – lots of ways to do it 🙂

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