Add loop shortcode

441 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
441
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Add loop shortcode

  1. 1. add_loop_shortcode.php 2011-11-06<?php/*Plugin Name: Loop ShortcodePlugin URI: http://semperfiwebdesign.com/Description: Adds a [loop] shortcode for embedding The Loop.Version: 2.0Author: Semper Fi Web DesignAuthor URI: http://semperfiwebdesign.com/*/add_shortcode( loop, pdb_sfwd_loop );function pdb_sfwd_loop( $atts, $content = null ) { $atts = shortcode_atts( array( /*** filter shortcode options ***/ "pagination" => true, "query" => , "category_name" => , "post_type" => , "order" => , "orderby" => , "meta_key" => ), $atts ); $the_query = new WP_Query(); if( $atts[pagination] == true ) $atts[paged] = get_query_var(paged); unset($atts[pagination]); $the_query->query( http_build_query( $atts ) ); ob_start(); /*** output buffering for convenience***/ while ( $the_query->have_posts() ) : $the_query->the_post(); $id = $the_query->post->ID; /*** allow use of id variable ***/ $content = str_replace( $id, "$id", $content ); echo do_shortcode ( $content ); /*** run shortcodes in the loop ***/ endwhile; if( $pagination == true ) { ?> <div class="navigation"> - 1/2 -
  2. 2. add_loop_shortcode.php 2011-11-06 <div class="alignleft"><?php previous_posts_link( « Previous )?></div> <div class="alignright"><?php next_posts_link( More »,$the_query->max_num_pages ) ?></div> </div><?php } wp_reset_postdata(); return ob_get_clean(); /*** return output buffer contents ***/}?> - 2/2 -

×