Show content on basis of logged in status of users in bbPress

No big deal here, just basic php stuff here. Here I will show how to use bb_is_user_logged_in function to dynamically produce output on the basis that the user is logged in or not.

Example #1 (Show ads only for non-logged in members and not for logged in members)

<?php
    if ( bb_is_user_logged_in() ) {
/* Add adsense or other ad code here*/
    }?>

Example #2 (Show some content only if the user is logged in)

<?php
    if ( bb_is_user_logged_in() ) {
/* Add the private content here or some code */
    }?>

Example#3 (Do more stuff)

<?php
    if ( bb_is_user_logged_in() ) {
/* You are logged in – do something for members */
    }
    else {
/* You are not logged in – do something for guests */
    }?>

So you can do anything on the basis that the current user is logged in or not. Need more help? Ask in the comments and I will be glad to help you out.


Comments

13 responses to “Show content on basis of logged in status of users in bbPress”

  1. hi

    where i must pt those code? in which file?

    thanks

    1. where do you want them?

      1. http://www.pokerbastards.com/forum/forum.php?id=1

        and is it possible to set up this for a whole category?

        (i can stop bothering you by posting only here OR on bbpress forum as you want ;))

        1. Its ok here. You need to edit forum.php file of your theme for making change in the content area. If you want to do in the header and footer, then header.php and footer.php is where you should make changes.

  2. ok
    I have edited forum.php and put the code inside but it doesn’t work, the content is still visible for unregistred users. I suppose i’m doing something wrong. Maybe i dont add the code where i should.
    Do i need to put something in particular between:
    /* Add the private content here or some code */

    1. yes! the code responsible for generating content should come in between it. If you are just trying to make your forum members only, then there are better approaches. If you just want to hide the content and display a message, you are on the right track.

  3. ok my mistake!
    I’m precisly trying to do a topic for members only.
    Sorry about that. If you have any tips on this matter, let me know 🙂

    thank you

  4. turunc4u Avatar
    turunc4u

    Hi, I want manual content to hide. Example I share some links in movie download topic but I want only registered user can see link. Is it possible. If you want to download links please sign up forum.

    1. Hi,
      Yes you can do something like all links are hidden (Login or Register link comes up there) for non logged in members and for logged in members actual post content is shown. You will need to hook up to the post output filter.
      If you want, you can hire me to do it – http://blog.ashfame.com/contact-ashfame/

        1. Cool! Let me know if you need my help with anything else.

          1. turunc4u Avatar
            turunc4u

            thanks