O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Display Content to Group Members

Problem

How do I display content only to members of a specific group?

Solution

Use the fb:if-is-group-member tag and specify the group ID. The simplest form is:

<fb:if-is-group-member gid="12345">Private content goes here</fb:if-is-group-member>

Discussion

You can use this tag in combination with the fb:else tag to display alternate content to people who aren’t in the group. The tag will default to checking for the loggedinuser, but you can also specify a different uid if you want to check a different member:

<fb:if-is-group-member gid="12345" uid="12345">
    Private content goes here
    <fb:else>
        Sorry! You're not in <fb:grouplink gid="12345"/>.
    </fb:else>
</fb:if-is-group-member>

Since groups support different roles (member, admin, officer), you can also use the fb:if-is-group-member to check for a user’s access level:

<fb:if-is-group-member gid="12345" uid="12345" role="admin">
    Private content for admins goes here
    <fb:else>
        Sorry! You're not an admin of <fb:grouplink gid="12345"/>.
    </fb:else>
</fb:if-is-group-member>

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required