Wishlist Member: Check Membership Level

Have you ever wanted to display different content based on Wishlist Member levels in WordPress? I did. After starting development on a recent project using WLM, I had a hard time finding documentation for specific hooks or functions. I even tried contacting the dev team, but never received a reply… and their documentation is pretty much non-existent. Basically if you are wanting anything other than out-the-box functionality it’s like pulling teeth as you won’t find much out there.

Anyway, if you are running a membership site via WLM and are looking to offer your content in a drip feed on the same page, and not just on a page by page basis, here’s what you can do:

The Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
// Get the current user level from WP
$user = wp_get_current_user();
 
// Get user levels from WishlistMembers
$levels = WLMAPI::GetUserLevels($user->ID);
 
// Then run the check for the level you want like this:
if(in_array('silver', $levels)){
  //  Display silver level content here
}
elseif (in_array('gold', $levels)){
   // Display gold level content here
}
?>
Continue Reading...

WordPress Taxonomies: Displaying Terms as Text

While using custom post types on a recent site, I ran into a situation where I wanted to list the terms(taxonomies) associated to a post. The function get_the_terms worked great, but I wanted to list the terms as text and not URLs. The first thing that came to mind was to use “strip_tags”, but that just felt dirty… so here’s a simple solution to display a post’s terms as text and not URLs.

The Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php function get_language_terms($args) {
            // Get terms for post
            $terms = get_the_terms( $post->ID , $args );
 
            if ( !empty( $terms ) ):
                // Loop over each item since it's an array
                foreach( $terms as $term ) {
                    // Print the name method from $term which is an OBJECT
                    echo $term->name;
                    // Get rid of the other data stored in the object, since it's not needed
                    unset($term);
           } endif;
 
} ?>

Then place this inside the loop and specify the argument for which taxonomy you are wanting to list terms for.

1
<?php get_language_terms('taxonomy_slug_goes_here'); ?>

I hope this can help someone else as well!

Continue Reading...

Mobile Friendly WordPress Development

A few months back I was searching for a good solution for optimizing a WordPress theme for mobile use. I didn’t find anything that great as far as plug-ins go, so I moved into searching for a simple php function that might work and I ran across this solution on mobiforge.com It did almost everything I wanted it to do. The algorithm used is fairly lightweight—the code is mostly based on a list of about 90 well-known mobile browser User-Agent string snippets, with a couple of special cases for Opera Mini, the W3C Default Delivery Context and some other Windows browsers. The code updates the header information and then redirects the user to a mobile version of the site. I wanted to modify this a little so that instead of redirecting a user to a new url, it would simply deliver different content or styles depending on what type of device they were using.

So, below is a very compact php mobile detection method. Of course this can be used on any php site, but I wanted to focus on implementing it with a WordPress theme. To start, include this in the functions.php or header.php file.

The Code:
1
2
3
4
5
6
7
8
9
10
<?php 
function is_mobile() {
	$regex_match="/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|";
	$regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|";
	$regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|";	
	$regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|";
	$regex_match.="jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220";
	$regex_match.=")/i";		
	return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']));
} ?>

Examples

Now, you can use this method to deliver any mobile specific content or styles. For example, if you wanted to use a different stylesheet on a mobile device you could do the following:

1
2
3
4
5
6
7
8
9
10
11
<link rel="stylesheet" type="text/css" media="all" href="
<?php
if(is_mobile()) { 
//load mobile stylesheet
echo "/css/mobile.css";
} else {
//load normal WP stylesheet
echo bloginfo( 'stylesheet_url' );
}
?>
"/>

Another example would be if you wanted to show different content for mobile vs. desktop. This can easily be accomplished by using custom fields. We would set up two custom fields in our WordPress template, one for normal content and one for mobile. We would then use the same statement as above to show one or the other:

1
2
3
4
5
6
7
8
9
<?php
if(is_mobile()) { 
//show mobile content
echo  get_post_meta($post->ID, 'mobile-content', true);
} else {
//show non-mobile content
echo  get_post_meta($post->ID, 'content', true);
}
?>

I hope this lightweight code can you help as it has been a great tool for me in developing mobile themes that can be easily managed by my clients via WordPress.

Continue Reading...

It’s Time to Shopp

I was recently given the opportunity to develop an eCommerce site for a client of mine.  I had developed a few eCommerce sites previously, all on different platforms, but for this project we wanted to go with WordPress as the CMS, and so my mind started to ponder back to eCommerce plug-ins I had used on previously.  Honestly the only remotely good one was WP eCommerce, and I actually ended up have a lot of issues with implementing it, as it was very “buggy” at times.  So I set out to hopefully find a new solution that would integrate as an eCommerce platform with WordPress and that’s when I came across Shopp.

After reading through the documentation and watching a few of the demo videos I was pretty much sold, but knew that I wouldn’t really know how good of fit it would be until I was able to install it in my own WP environment.  Unfortunately this became a little bit of a leap of faith as Shopp is not a free plug-in.  I had to pony up the doe before I would even know if it was good or not.  This is why I am writing this review and tutorial, to hopefully help people make a decision on using Shopp without having to feel like they might be wasting their money in making the “$55 blind leap”.

Luckily for me, I wasn’t let down. Overall I have to say I give the plug-in an 8.5 out

Continue Reading...

Flutter: WordPress Custom Fields Made Easy

Update: Flutter is no longer compatible with latest versions of WordPress (3.0+). An alternative solution is a fork of Flutter called Magic Fields.

For the past few years I have been referring clients to WordPress as my preferred CMS solution.  I have found WordPress to be a wonderful solution for many of my clients.  There are a few areas that could use some improvement, but honestly I don’t know of a perfect CMS out there, do you?  As most WP developers know, custom fields are the key to using it as a successful CMS, and there have been some major improvements in last few years to help make it easier to implement custom fields into your template files, but in my experience it seems that not all of my clients fully understand how to use custom fields they way they are built into WordPress by default.

custom-fields

There are ways to hack around and make it easier for your client, I even wrote an article over at Foraker.com that explains how incorporate the power of custom fields in WordPress, and this way may be easy to understand for people familiar with WP and PHP but for my clients  I feel that the default layout of using custom fields is a little hard to understand.  Mostly I have had issues with clients wanting to the custom field to be an image and the only way to do this is for the client to upload the photo first via the

Continue Reading...
Newer Posts