Add Loop Buddy Support to Genesis

Add this code to the functions.php file of your Genesis Child theme to add support for iThemes Loop Buddy.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
add_theme_support('loop-standard');
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;
    }
}
 
remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'add_loopbuddy_support');
function add_loopbuddy_support() {
	if (!dynamic_loop()) :
	if ( is_page_template( 'page_blog.php' ) ) {
		$include = genesis_get_option( 'blog_cat' );
		$exclude = genesis_get_option( 'blog_cat_exclude' ) ? explode( ',', str_replace( ' ', '', genesis_get_option( 'blog_cat_exclude' ) ) ) : '';
		$paged   = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
 
		/** Easter Egg */
		$query_args = wp_parse_args(
			genesis_get_custom_field( 'query_args' ),
			array(
				'cat'              => $include,
				'category__not_in' => $exclude,
				'showposts'        => genesis_get_option( 'blog_cat_num' ),
				'paged'            => $paged,
			)
		);
 
		genesis_custom_loop( $query_args );
	} else {
		genesis_standard_loop();
	}
	endif;
}