Skip to:
Content
Pages
Categories
Search
Top
Bottom

Getting bbPress and WordPress to talk to each other

  • @vilimaunula

    Participant

    I’m not sure if I should ask this here or over at WordPress.org, but perhaps this is more of a bbPress question in the end.

    I have the latest bbPress and WordPress installations, and both are running fine. The user databases are integrated, and I have also managed to get bbPress to use my WordPress theme after some poking around.

    What I actually did with the theme integration was that I made bbPress to call the WordPress header and footer files instead of the bbPress ones, having in turn modified the WordPress files in a way that everything except for the page-specific content is in those two files. This way, the forum shows up where the WordPress content (posts, pages, etc.) would otherwise go. Life is good.

    My problem now is that I would like WordPress to recognize bbPress when it is serving a bbPress page. In other words, I would like to have something like an “if” condition for example in my WordPress header that checks whether the page currently being shown is a bbPress page. If I could do that, then I could do something like “if bbPress then echo bbPress headers, else echo WordPress headers”.

    The most basic solution that I could come up with was the following: before having a bbPress page call the WordPress header, introduce a variable like “$forumpage” and set it to “true”. Then simply include a check in the WordPress header that checks whether $forumpage is “true”. For some reason, however, this doesn’t work as the variable seems to get erased.

    I also tried something like using the condition if($forums) in the WordPress header, which I saw was in bbPress, but that gave no results, either.

    There probably is a(n easy) solution to all this, so I would really appreciate it if someone could point me to the right direction. I’ve spent most of the evening working on this, and have tried just about everything that I can think of and have read about on these forums and over at WordPress.org, but alas without the desired results.

    Thanks for reading!

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

    Member

    I have no idea how the bb environment can be detected, but I think I know why your $forumpage hack didn’t work; the WP headers are in different files and such.

    When setting $forumpage, try something like this:

    global $forumpage = true;

    When checking if $forumpage is true, do it something like this:

    global $forumpage;
    if( $forumpage = true )
    {
    ...
    }

    If you tell PHP that you want the global variable $forumpage it should work.

    Not too confident about this, but that should tell PHP to make them global (ie. available everywhere). Otherwise you’ll probably be calling different variables called $forumpage.

    @vilimaunula

    Participant

    Brilliant! I didn’t know that global variables like this exist in PHP (I’m a hobbyist). Thanks a bunch!

    Btw, I had to change the declaration from

    global $forumpage = true;

    to

    global $forumpage;

    $forumpage = true;

    It gave me an error otherwise.

    @fel64

    Member

    Thanks for coming back and telling me :D

    @arlo

    Member

    My site has a similar integration. I tossed around the idea of doing a conditional header like you describe, but in the end it was just simpler to have a second header file specific for bbpress, which is basically a copy of the WP one with some of the required bbpress stuff thrown in.

    @vilimaunula

    Participant

    I thought about having separate headers, but concluded that sweating blood and tears now is easier than having to remember later that I have near-identical info in two different places. But it is really up to your own preferences, I suppose.

    Now that I’m able to make WordPress recognize when it’s serving bbPress pages, I can also modify the sidebar and other design features accordingly on the fly, which I think is really quite nice.

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