Code, Plugins

Get object IDs per post for the WooCommerce Memberships plugin

The function below will show you how to get the page/post IDs or taxonomy term IDs for restricted content for chosen WooCommerce Memberships levels which have been assigned to a post or page.

Recently I needed to get each restricted category ID for the WooCommerce memberships plan associated with a particular page. Unfortunately that function doesn’t exists in the plugins helper functions. With a little digging we came up with a good solution that will return the object IDs for either a 'post_type' or a 'taxonomy' object which has been content restricted.

This is useful if you are trying to query those associated posts or categories from a particular post or page. You may even want to link an associated page or category. Using the IDs you can easily use a common WordPress function to do so. The page/posts or taxonomy term ID’s will be returned in an array.

Continue Reading …

Code, Themes

Pure javascript multi-level navigation in WordPress

For some time now I have been using a pure javascript drop down menu script called Drop in my WordPress themes for simple mobile friendly multi-level navigation. I really like it because it doesn’t rely on any external libraries like jQuery. The library was created and is maintained by Chris Ferdindandi.

For the latest versions of Drop (version 6.1.1 at the time of this writing) I have needed to create a custom Walker Nav to add data attributes to list items which have sub-menus, initialize drop with some custom options, and use another small library called Astro (also maintained by Chris, and also written in pure javascript) to expand and collapse the menu on small screens.

Continue Reading …

Code, Themes

Responsive Featured Image function in WordPress themes

[UPDATE – May 23rd ’14]

I have included an update to this article which features new code and a downloadable plugin. Please note that this post simply shows a method I use to implement featured images into projects I am working on. If you attempt to use this method in your projects you could run into unforeseen issues. This is especially true if you are not familiar with developing in PHP or WordPress. I don’t recommend trying to implement this into your theme as such as it is not simply obtained by copy and paste. This article simply shows a method I use.

Continue Reading …

Code, Themes

Simple Featured Image Function for your WordPress theme!

Many times in theme development when we want to include a featured image we may just include the post thumbnail function like this example taken from the codex:

<?php 
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
  the_post_thumbnail();
} 
?>
<?php the_content(); ?>

This may be fine. But what if you want to include the featured image in various places in your theme with different attributes such as image size? You could paste this function like this the_post_thumbnail('large'); but you also want to check if the post or page has a featured image in which you would paste the code above with the if statement has_post_thumbnail() as shown above.

Continue Reading …