If you have the Loop Buddy plugin and want to add support for it in your WordPress theme, you use the function dynamic_loop.
Step 1: Defining the function
This needs to be added to your functions file.
<?php
//LoopBuddy Support
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;
}
}
Step 2: Calling the function from within your template
Here is an example of what it might look like in a content.php (or similar) template file.
<section>
<h2>Content Title</h2>
<p>Congratulations, you have just built your own WordPress theme from scratch.</p>
<?php if (!dynamic_loop()) : ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<small><?php the_time('F jS, Y') ?> by <?php the_author() ?></small>
<div>
<?php the_content('Read the rest of this entry »'); ?>
</div>
<p>
Posted in <?php the_category(', ') ?> <strong>|</strong><?php edit_post_link('Edit','','<strong>|</strong>'); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</p>
</div>
<?php endwhile; endif; ?>
<?php endif; ?>
</section>