Skip to:
Content
Pages
Categories
Search
Top
Bottom

wp-bb, is it possible to define conditional tags for bbpress?

  • @ganzua

    Member

    In wordpress you can use conditional tags -> http://codex.wordpress.org/Conditional_Tags to display different content according to the page that is being displayed.

    Well, after having wp and bb integrated and displaying wp sidebar in bbpress, is it possible to define conditional tags for bbpress or bbpress folders?

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

    Member

    @ganzua

    Member

    Hey fel64!

    Thanks for the answer. Do you know if is it possible to copy these functions in your wordpress theme functions file?

    In fact I only need to define one conditional tag; is_bbpress(), so I can display different advertising blocks in the wordpress sidebar when loading bbpress.

    @fel64

    Member

    Might have asked what you wanted straight away. :/ So open your theme’s functions.php and add this:

    function is_bbpress() {
    global $bb;
    return $bb ? true : false;
    }

    Off the top of my head, but should work anyway. Try it.

    @ganzua

    Member

    Hey fel64

    I tried and it seems to work until you make an is_single() statement because then, wordpress takes bbpress subpages; topics, profiles… as if they were wp single entries.

    Is it possible to catch the whole bbpress installation with your function?

    @fel64

    Member

    What’s the actual problem? How are you using it, what do you expect it to do, what exactly is it doing?

    @ganzua

    Member

    “What’s the actual problem? How are you using it, what do you expect it to do, what exactly is it doing?”

    ->

    In my wp-bb integration, bbpress is integrated in wordpress and the forum uses the wordpress sidebar. I want to insert advertising blocks in the free space that I have in the bottom of the sidebar.

    I’m trying to use wp conditional tags to display different ad blocks because in some pages I have space enough for one block, and in other pages I have space for two or three blocks.

    In wp single pages I can display at least two 120×600 blocks so I’m using is_single() but I realized that these blocks are appearing in the bbpress forum too! and I just have no space enough for them so I want to change them for a 125×125 block when the forum is displayed or perhaps I could remove all ads when bbpress displayed.

    So “How are you using it” -> after copy/pasting your function in my theme functions file, I inserted this code in my sidebar;

    <?php if (is_bbpress()

    || is_archive()

    ) { ?>

    <!– 125×125 block –>

    <?php } ?>

    <?php if (is_single()

    || is_page()

    ) { ?>

    <!– 160×600 block –>

    <?php } ?>

    “what do you expect it to do” -> showing different ads blocks in the sidebar when bbpress displayed

    “what exactly is it doing” -> is showing the blocks I set for is_single ()

    @fel64

    Member

    Actually the function works just fine, you’re just expecting it to work differently. Try using different flow control or rewriting your logic.

    if( blah_is_true() ) {

    } elseif( foo_is_true() ) {

    } elseif( third_thing_is_true() ) {

    } else {
    // default
    }

    The elseifs mean that if a previous if statement was true, none of the successive ones will be tried. That way, if it is bb, it won’t even check if it’s single or a page.

    Alternatively,

    if( ( is_single() || is_page() ) && !is_bbpress() ) {

    }

    will work just fine.

    If you’ve integrated bb into wp that way, of course some of the WP template tags will work that way. If you wanted everything else to return false when you loaded bb, you’d have to do this:

    function adjust_flags_to_bb() {
    global $wp_query;
    $wp_query->init_query_flags();
    }
    add_action('bb_init', 'adjust_flags_to_bb', 999);
    //not sure if that's the right action, but meh

    but that’s really quite unnecessary.

    @ganzua

    Member

    Thanks again fel64,

    I tried the second one because it seemed the easiest to me :) and I think it is working ok.

    This -> ‘ && !is_bbpress() ‘ means “exclude bbpress”, doesn’t it?

    The first one, ” elseif “, is quite interesting -> in my wp custom theme, I turned index.php into a cms which displays what’s new in the whole web, and I created a static page called “blog” to display the “blog” itself.

    Well, with this configuration, whenever you make a is_home statement , the function points to the static page I created and called “blog” and I can’t find the way to make the function to point to my custom index.php main page. Perhaps because the static page I called “blog” has the loop?

    @ganzua

    Member

    Well, more or less this is working but now bbpress goes to the last “else” statement and I don’t know why;

    <?php if ( is_page() )

    { ?>

    <!– one ad block –>

    <?php } elseif ( is_single() && !is_bbpress() )

    { ?>

    <!– two ad blocks –>

    <?php } else

    { ?>

    <!– no ads –>

    <?php } ?>

    I haven’t try your third option yet because I didn’t understand quite enough.

    @ganzua

    Member

    oops! sorry, I didn’t define what happens whe is_bbpress(), I just exclude it.

    now it is working;

    <?php if (

    is_page()

    )

    { ?>

    <!– one ad block –>

    <?php } elseif (

    is_single()

    && !is_bbpress()

    )

    { ?>

    <!– two ad blocks –>

    <?php } elseif (is_bbpress()

    )

    { ?>

    <!– half ad block –>

    <?php } else

    { ?>

    <!– no ads –>

    <?php } ?>

    @ganzua

    Member

    I uploaded to my web so anyone else interested can check.

    Thanks for your help fel64!

    @fel64

    Member

    No problem. :)

    Option #3 was a throwaway possibility, not really meant for actual use as it’s rather silly.

    whatever && !is_bbpress() means, literally, that whatever has to be true AND is_bbpress() is not true. The ! operator inverts the boolean meaning, so true becomes false and vice versa. If is_bbpress() is true, ! makes it read as false. If false, it makes it read as true.

    By the way, the backtick ` that indicates code is on the top left button on most English and European characters. :)

    @ganzua

    Member

    Thanks for the explanation, do you have to put && insted of ||

    “By the way, the backtick ` that indicates code is on the top left button on most English and European characters. :)

    -> sorry for that because I have it quite difficult, I’m using a german keyboard and OS is in Spanish :s

    @fel64

    Member

    && and || are just two different things. && means both things have to be true for the entire result to be true, || means just one needs to be true for the entire result to be true.

    On a german keyboard I think it’s the capital letter on button just left of backspace. On a spanish layout it should be the one two left of enter, the one that also gives you ^ and [ (if I’m looking at the diagrams right). :)

    @ganzua

    Member

    thanks a lot for the explanation fel64!

    @ganzua

    Member

    I’m realizing that I have more undefined pages. I have a custom login page here -> http://www.joseperdicion.com/wordpress/wp-login.php , ultimate tag warrior pages, for example this one; http://www.joseperdicion.com/wordpress/index.php?tag=onirica

    Besides, some single pages are not tall enough to put two ads blocks in the sidebar.

    Where did you read how to build ” is_smthing () ” functions? I wonder if I coud build one for is_login, is_tag (I presume this one will be solved in wp 2.3), is_aparticularfolder.

    Is it possible to build a conditional tag for page height?. For example; ” if it is taller than x number of lines then put two ads blocks”.

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