Cleverness – WordPress Resources

How-To

WordPress Gallery with Categories

Recently I needed to recreate a specific gallery format in WordPress.
There are probably better ways to go about it, such as custom post types, but I needed something quick and easy.

The main gallery page needed to have a list of “categories” that were represented by images.
I used a WordPress Page that consisted of:

Each “category” was an image that linked to a WordPress Page.

On the category pages, for each gallery item, there needed to be a caption on top of the image, the image with no link, and a description under the image.
For each of … continue reading

Updated BuddyPress User Roles Code

My post on adding user types to WordPress and Buddypress has been very popular.

This code will soon be available as a plugin.

I’ve updated the code so it’s cleaner and easier to implement. This code also works with or without allowing users to add new sites.

This only works for BuddyPress running on the multisite version of WordPress.
If you’re using the regular version, someone else has a plugin available for that: WP Roles at Registration. It works for BuddyPress (but not the multisite version).

Instructions

Set up your custom WordPress roles using Capability Manager or a similar … continue reading

User Types in BuddyPress – Assign xprofile Groups

As requested by Janis, here is the code I use to show only certain xprofile groups to each user type. In the default BuddyPress theme, profile fields without a value aren’t shown, so only the ones for that group will appear to the public.

You will need to replace a function call in your BuddyPress theme, in /members/single/profile/edit.php. It is at line 12 in mine.

Find

And replace it with this:

In /plugins/bp-custom.php place the following code. You will need to edit it to fit your user type and profile group needs.… continue reading

Adding User Types to WordPress and BuddyPress – with User Blogs

There is a new version of this code located at http://cleverness.org/2011/01/27/updated-buddypress-user-roles-code/. Please use that code and leave all comments on that page.

I’ve previously talked about adding user types to BuddyPress. I’ve found out recently that if you allow new users to create their own blogs, you will need to add the following code to your functions.php file.… continue reading

Get Categories Author has Posted in for Custom Post Types

I needed to list all the categories of a custom post type that an author had posted in.

I found code to do that with regular posts in the wordpress.org forums and I modified it to use with custom post types.

Be sure to replace customposttype with the name of your custom post type.

Place this into your theme file where you want the list to appear.… continue reading

Limit Number of Posts Per User in WordPress

This code will limit the number of posts a user can make.

At first, I was trying to limit each user to one post and I had that working. Then I realized that I needed to have different numbers of posts for different users, so I created an option in a user’s profile that only people with the right capability (manage_options) can edit. I’ll be changing this in the future for that number to be automatically changed depending on a user’s subscription type, but I needed this for testing purposes.

The option in the profile shows up under the contact … continue reading

Add User Types to WordPress and BuddyPress

One thing I needed to do was allow people to choose a user type at registration. I also needed the user to be assigned a custom Role based on their user type.

Show number of posts in a category

Tonight I needed to figure out how to display the number of posts that were in a specific category.

This post on Getting the number of posts per category showed me how to do that.

This goes into your template where you want the number to appear:

Replace category-slug with the slug of your category.… continue reading

Replacing Core Functions

Replacing template core functions is easy and doesn’t require editing core files.

Copy the code for that function to functions.php in your theme, change the function name, and call it in your template using it’s new name.… continue reading

Yearly Archives

Place the following in functions.php to list the archives for a specific month and year:

This is what you will add to your template file:


If you’ve been blogging for a number of years, it can sometimes be helpful to list your archives by years, then by months, then by days.

If you use this method, your archive page will list every year you have a post in. Then when you click on a year, it will take you to a list of the months you posted in that year. Then when clicking on a month, you go to a … continue reading