Skip to:
Content
Pages
Categories
Search
Top
Bottom

Highlighting the current forum tab

  • Hi, I’m making a navigation and was looking for help with highlighting the links, depending what page/forum you are on.

    I have a homepage nav link like:

    <a href="/forum">Mainpage</a>

    how can I add class=”current” and highlight the link when on the mainpage?

    I also run a list of the forums in a similar style

    <?php foreach ( $forums as $forum ) : ?>
    <a class="forum-link" href="<?php forum_link( $forum->forum_id ); ?>"><?php forum_name( $forum->forum_id ); ?></a>
    <?php endforeach; ?>

    Is there a way to add class=”current” depending on what forum the user is browsing?

    I know this can be done on wordpress, but I dont know the functions for bbpress yet, and good info is far and wide.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Your code is much cleaner for my use.

    I check a WP theme and I’m assuming it’s something like this…

    <?php if (is_page()) { $highlight = "forum-link"; } else {$highlight = "current"; } ?>
    <?php foreach ( $forums as $forum ) : ?>
    <a class="<?php echo $highlight; ?>" href="<?php forum_link( $forum->forum_id ); ?>"><?php forum_name( $forum->forum_id ); ?></a>
    <?php endforeach; ?>

    but it’s not is_page(), it’s something else.

    BTW the code you have does work in front-page.php but does not in forum.php

    I just noticed that actually :)

    Back to the drawing board…

    I found this post https://bbpress.org/forums/topic/functions-for-generating-a-menu-of-wordpress-pages

    This doesn’t work for me, it makes my forum blank before even asking for the script. When I create a function.php file and put everything in it. I hope this can help steer you into the right direction.

    I found a cheap and nasty way to do it via forum ID, anything else just highlights every tab :(

    <li<?php if (bb_is_front() && $forumpage == false) echo " class="new" id="current""; ?>><a href="/boards" title="Forums">Mainpage</a></li>

    That will highlight the mainpage tab.

    <li<?php if ($forum_id == 1) {echo " class='new' id='current'";} ?>><a href="/boards/forum/first-forum">first-forum</a></li>
    <li<?php if ($forum_id == 2) {echo " class='new' id='current'";} ?>><a href="/boards/forum/2nd-forum">2nd-forum</a></li>

    That will highlight forums by ID.

    Hope this helps you along :)


    psycheangels
    Member

    @psycheangels

    before the loop

    $forumselect = get_forum_id();

    and in the loop

    <li class=”<?php if ( get_forum_id() == $forumselect ) : ?>selected<?php else: ?>forum_subforum<?php endif; ?>”>

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