PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Listing Categories

s2Member Plugin. A Membership plugin for WordPress®.

Listing Categories

Postby vitorclaw » April 8th, 2011, 2:48 pm

Hey guys, first I would like to say that s2member is an amazing plugin really easy and simple to customize. You guys must be proud of it.

Now my question:

I have a blog where I display the 10 latest posts, and on the sidebar I have a list with all my categories generated by wp_list_categories();

The thing is, I would like to exclude categories that are blocked for a certain type of user. (I'm currently using the Alternative view protection, but it doesn't affect this function)

Is there any way to do that?

What i could do if there isn`t any avaiable option to do that is to get all Categories that are blocked ID and insert it into the function so it would be something like:
$blocked_cats;
wp_list_categories("exclude=$blocked_cats");

But I don`t really know how to get those categories.

So I hope you guys can help me. Thanks
User avatar
vitorclaw
Registered User
Registered User
 
Posts: 16
Joined: April 8, 2011

Re: Listing Categories

Postby vitorclaw » April 8th, 2011, 2:58 pm

Nevermind, just found the solution, for future reference:

Example #4: Checking Category Restrictions.

Code: Select all
<?php
if 
($categories = get_categories ())
    {
        foreach ($categories as $category)
            {
                if (!is_permitted_by_s2member ($category->cat_ID, "category"))
                    continue;
                /* Skip it. The current User/Member CANNOT access this Category,
                or any Posts inside this Category, or any of its sub-Categories. */
            }
    }
?>


EDIT:

By the way, the only way to display categories that i found is doing something like this:

Code: Select all
if ($categories = get_categories ()) {
    $i = 0;
    foreach ($categories as $category) {
        if (!is_permitted_by_s2member ($category->cat_ID, "category"))
            continue;
        $variables = get_object_vars($category);
        echo $variables['name'];
        $i++;
    }
}
 
Last edited by Cristián Lávaque on April 8th, 2011, 8:06 pm, edited 1 time in total.
Reason: Improve code readability. http://www.primothemes.com/forums/viewtopic.php?f=36&t=2780
User avatar
vitorclaw
Registered User
Registered User
 
Posts: 16
Joined: April 8, 2011

Re: Listing Categories

Postby Cristián Lávaque » April 8th, 2011, 8:11 pm

I'm glad you found the solution. :)

I'm just curious, what do you need the $i there for?

For the benefit of others: that example can be found under WP Admin -> s2Member -> API / Scripting -> Advanced Query Conditionals.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Listing Categories

Postby vitorclaw » April 8th, 2011, 8:26 pm

Hi Cristián, theres no need for it. I was trying another solution before and just forgot to remove it hehe.
User avatar
vitorclaw
Registered User
Registered User
 
Posts: 16
Joined: April 8, 2011

Re: Listing Categories

Postby Cristián Lávaque » April 8th, 2011, 8:56 pm

LOL I know what you mean. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 1 guest

cron