Written by on

Unleash the Power of LoopBuddy for Any WordPress Theme

LoopBuddy, by iThemes, is arguably one of the most powerful WordPress plugins available today. The ability LoopBuddy offers to users to easily modify the WordPress query used in retrieving content out of the database and then to also modify the look and layout display of the queried content without having to touch a single line of PHP code while using a visual editor opens up tremendous opportunities for developers.

Even with all of this power available to developers and users, there is still a catch: A WordPress theme needs to support the Loop Standard in order to take full advantage of the flexibility of LoopBuddy.

LoopBuddy currently works with any theme within that theme’s widget area, but to achieve maximum compatibility across the entire theme you need keep reading. A simple two-step process is all that is needed to make your current or future theme compatible with LoopBuddy. (There is currently a full webinar on this process in the WebDesign.com membership, but I’ll walk you through a simple example in this post.)

This two-step process consists of:

  1. Adding the necessary support for LoopBuddy into your active theme’s functions.php file
  2. Wrapping the theme’s current WordPress loop with a conditional statement. You may have to wrap multiple loops because many themes have different WordPress loops in different places. (Example of locations to look: index.php, single.php, page.php, archive.php, 404.php, etc)

Let’s start by looking at the two necessary code snippets you need to add to your active theme’s functions.php file:

First, we add the support for the Loop Standard by adding the following line of code:

add_theme_support('loop-standard');

Second, we add two PHP functions that define what is happening with the dynamic_loop():

if ( ! function_exists( 'dynamic_loop' ) ) {
	function dynamic_loop() {
		global $dynamic_loop_handlers;
		if ( empty( $dynamic_loop_handlers ) || ! is_array( $dynamic_loop_handlers ) )
			return false;
		ksort( $dynamic_loop_handlers );
		foreach ( (array) $dynamic_loop_handlers as $handlers ) {
			foreach ( (array) $handlers as $function ) {
				if ( is_callable( $function ) && ( false != call_user_func( $function ) ) ) {
					return true;
				}
			}
		}
		return false;
	}
}
if ( ! function_exists( 'register_dynamic_loop_handler' ) ) {
	function register_dynamic_loop_handler( $function, $priority = 10 ) {
		global $dynamic_loop_handlers;
		if ( ! is_numeric( $priority ) )
			$priority = 10;
		if ( ! isset( $dynamic_loop_handlers ) || ! is_array( $dynamic_loop_handlers ) )
			$dynamic_loop_handlers = array();
		if ( ! isset( $dynamic_loop_handlers[$priority] ) || ! is_array( $dynamic_loop_handlers[$priority] ) )
			$dynamic_loop_handlers[$priority] = array();
		$dynamic_loop_handlers[$priority][] = $function;
	}
}

The second part of this process is to locate the WordPress loops in the theme and wrap the loop with a PHP conditional statement that asks whether or not we are using the dynamic_loop() function to override the original loop. The code looks like this:

<?php if (!dynamic_loop()) : ?>
	ORIGINAL LOOP
<?php endif; ?>

To help give you an example, I have taken the free iThemes theme Elementary – Red and converted it to support LoopBuddy. You can compare both versions (Original | New) to see exactly what I’ve changed to enable this LoopBuddy support.

So what are you waiting for? You now have the power to make your current or next WordPress theme super powered with LoopBuddy.

Additional Reading and Resources:
LoopBuddy Sales Page
iThemes Codex on converting a theme to support LoopBuddy
WordPress Loop information (important to read if you want to learn more about the WordPress loop)
Download Original WordPress Theme
Download New WordPress Theme that now supports LoopBuddy

Comments

  1. Unfortunately, it’s not as easy as you make it out to be adding loopbuddy to an existing theme. The two samples you use are basic bare bones themes, Elementary Red and Twenty Eleven.

    It would be more helpful if you can show how to add loopbuddy to a complex theme from Themeforest or somewhere like that.

    Thanks

    • It actually is that easy. In last week’s WebDesign.com webinar I demonstrated how to hook up LoopBuddy with WooThemes, ElegantThemes, Genesis, several other robust themes as well.

      The goal is to identify the WordPress loop code and then wrap it with the conditional tag.

      Now I would venture to say that many of the “complex” themes at the themeforest are so poorly coded that they don’t even work correctly with the most popular WordPress plugins. Just search and you’ll find documentation of these poorly coded themes from developers who don’t follow WordPress standards. So before you start trying to get you themeforest theme converted to LoopBuddy, make sure it is correctly coded to save you from pulling your hair out.

      Since every theme requires the use of the WordPress loop then every theme has the capacity to support support LoopBuddy.

      • Hello,
        I have Headway installed and somehow the Loopbuddy quiry does not work at all…. I first used Types, then now on Custom Post Types UI… Do you have any idea why that might happen?

  2. Is LoopBuddy also to use with the theme Desk Mess Mirrored after I add code as mentioned above? (in functions.php)

    Being just a regular user (with only basic knowledge of php/wordpress) and would like to know if I am incorrect when I “just” copy and paste in the index.php / single.php and page.php the code after div id=”content” and just before that closing div?
    Would be awesome to use this amasing plugin.

    • oops, it does not accept all code? wanted to say code `if (!dynamic_loop()) :` after content div and code `endif; ` before closing content div. (sorry)

  3. I use a custon WP theme made with Artisteer ..and probably has to many loops in several places,

    Can i use loopbuddy by creating new empty pages and put the loopbuddy shortcode in them in order to have the custom loop?
    (not just inside widgets)

Respond

×

Sale Ends Today! Save 35% OFF BackupBuddy with coupon code BACKUPWP35