bbPress

Simple, Fast, Elegant

bbPress support forums » Plugins

Get Current Forum ID?

(5 posts)
  • Started 1 month ago by iuxc
  • Latest reply from iuxc
  • This topic is resolved

Tags:

  1. iuxc
    Member

    I'm attempting to create a side nav of all the forums on my site. When a user is viewing a certain forum, I want that "tab" to be highlighted using CSS.

    All I need is to assign a class="on" attribute to the forum [li] [/li] tag if it is the current forum being viewed. Anyone know how I can check the current forum against the forum id?

    Here's the code for my menu creation:

    <?php if ( bb_forums() ) : ?>
      <h3><?php _e('Forums'); ?></h3>
      <ul>
        <li <?php if ( is_front() ) : ?>class="on"<?php endif; ?>><a>">Overview</a>
        <?php while ( bb_forum() ) : ?>
          <li><a>"><?php forum_name(); ?></a></li>
        <?php endwhile; ?>
      </ul>
    <?php endif; // bb_forums() ?>
    Posted 1 month ago #
  2. iuxc
    Member

    Thanks for the suggestion. It didn't fix what I am trying to do.

    Basically, while the php is executing the while ( bb_forum() ) : loop, I need to check the current forum against the forum it is writing to the menu.

    If there are 4 forums in the while loop, I need it to check the current forum id against each forum id as it is writing it to html. If the current forum id matches the forum id it's writing, then it would add the class="on" attribute to the li tag.

    Posted 1 month ago #
  3. Untested and YMMV:

    $current_forum_id = get_forum_id();
    
    while ( bb_forum() ) {
        $class = '';
        if ($current_forum_id == get_forum_id()) {
            $class = 'on';
        }
    }
    Posted 1 month ago #
  4. iuxc
    Member

    Thanks! Worked perfectly. :)

    Posted 1 month ago #

RSS feed for this topic

Reply

You must log in to post.

Code is Poetry.