SlideShare a Scribd company logo
add_loop_shortcode.php                                                  2011-11-06
<?php
/*
Plugin Name: Loop Shortcode
Plugin URI: http://semperfiwebdesign.com/
Description: Adds a [loop] shortcode for embedding The Loop.
Version: 2.0
Author: Semper Fi Web Design
Author 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 -
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 -

More Related Content

PDF
Codeigniter : Two Step View - Concept Implementation
PDF
Pemrograman Web 9 - Input Form DB dan Session
PDF
Codeigniter : Using Third Party Components - Zend Framework Components
PDF
Pemrograman Web 8 - MySQL
PDF
RESTful web services
PPTX
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
PDF
Phinx talk
PDF
Blog Hacks 2011
Codeigniter : Two Step View - Concept Implementation
Pemrograman Web 9 - Input Form DB dan Session
Codeigniter : Using Third Party Components - Zend Framework Components
Pemrograman Web 8 - MySQL
RESTful web services
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Phinx talk
Blog Hacks 2011

What's hot (20)

PDF
Mojolicious: what works and what doesn't
KEY
Phpne august-2012-symfony-components-friends
PPT
Dance for the puppet master: G6 Tech Talk
ODP
PDF
Advanced Querying with CakePHP 3
PDF
YAPC::Asia 2010 Twitter解析サービス
PPTX
Webrtc mojo
ODP
Mojolicious on Steroids
PPTX
Tax management-system
PPTX
An introduction to Laravel Passport
PPTX
15. CodeIgniter editarea inregistrarilor
PDF
Extending the WordPress REST API - Josh Pollock
PDF
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
PDF
Check username availability with vue.js and PHP
PDF
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
KEY
Mojo as a_client
KEY
Mojolicious - A new hope
PDF
Developing apps using Perl
PDF
Practica csv
DOCX
Mojolicious: what works and what doesn't
Phpne august-2012-symfony-components-friends
Dance for the puppet master: G6 Tech Talk
Advanced Querying with CakePHP 3
YAPC::Asia 2010 Twitter解析サービス
Webrtc mojo
Mojolicious on Steroids
Tax management-system
An introduction to Laravel Passport
15. CodeIgniter editarea inregistrarilor
Extending the WordPress REST API - Josh Pollock
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
Check username availability with vue.js and PHP
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
Mojo as a_client
Mojolicious - A new hope
Developing apps using Perl
Practica csv
Ad

Viewers also liked (6)

PDF
Esta es la cara que pone cuando llega su recibo de luz 2
DOCX
DOCX
Supervisão organização e liderança
PPTX
Gangguan pada tulang
PPTX
Presentación1 tics
DOC
Identificação
Esta es la cara que pone cuando llega su recibo de luz 2
Supervisão organização e liderança
Gangguan pada tulang
Presentación1 tics
Identificação
Ad

Similar to Add loop shortcode (20)

PDF
The Zen of Lithium
PDF
Virtual Madness @ Etsy
PDF
Mashing up JavaScript – Advanced Techniques for modern Web Apps
PDF
Mojolicious. Веб в коробке!
PDF
Mashing up JavaScript
DOC
PDF
Bag Of Tricks From Iusethis
PDF
WordPress REST API hacking
PDF
Hacking Movable Type
PDF
You're Doing it Wrong - WordCamp Orlando
PDF
Unit testing after Zend Framework 1.8
PPTX
Zero to SOLID
PDF
Be RESTful (Symfony Camp 2008)
PDF
Symfony without the framework
PDF
関西PHP勉強会 php5.4つまみぐい
PPTX
What mom never told you about bundle configurations - Symfony Live Paris 2012
 
PDF
Rails 3: Dashing to the Finish
PDF
Silex Cheat Sheet
PDF
Silex Cheat Sheet
PDF
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011
The Zen of Lithium
Virtual Madness @ Etsy
Mashing up JavaScript – Advanced Techniques for modern Web Apps
Mojolicious. Веб в коробке!
Mashing up JavaScript
Bag Of Tricks From Iusethis
WordPress REST API hacking
Hacking Movable Type
You're Doing it Wrong - WordCamp Orlando
Unit testing after Zend Framework 1.8
Zero to SOLID
Be RESTful (Symfony Camp 2008)
Symfony without the framework
関西PHP勉強会 php5.4つまみぐい
What mom never told you about bundle configurations - Symfony Live Paris 2012
 
Rails 3: Dashing to the Finish
Silex Cheat Sheet
Silex Cheat Sheet
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011

More from Peter Baylies (8)

PDF
Membership Plugins in WordPress
PDF
WordPress Server Security
PDF
Debugging and Profiling in WordPress: What is My Site Doing?
PDF
Speed Up That Site! - a guide to caching plugins
KEY
Doing cool stuff with WordPress
PDF
Mastering the shortcode api
PDF
Add tag shortcode
PDF
Add title shortcode
Membership Plugins in WordPress
WordPress Server Security
Debugging and Profiling in WordPress: What is My Site Doing?
Speed Up That Site! - a guide to caching plugins
Doing cool stuff with WordPress
Mastering the shortcode api
Add tag shortcode
Add title shortcode

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation theory and applications.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
KodekX | Application Modernization Development
Mobile App Security Testing_ A Comprehensive Guide.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Building Integrated photovoltaic BIPV_UPV.pdf
cuic standard and advanced reporting.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Spectral efficient network and resource selection model in 5G networks
The Rise and Fall of 3GPP – Time for a Sabbatical?
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Weekly Chronicles - August'25 Week I
The AUB Centre for AI in Media Proposal.docx
Encapsulation theory and applications.pdf
Approach and Philosophy of On baking technology
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KodekX | Application Modernization Development

Add loop shortcode

  • 1. add_loop_shortcode.php 2011-11-06 <?php /* Plugin Name: Loop Shortcode Plugin URI: http://semperfiwebdesign.com/ Description: Adds a [loop] shortcode for embedding The Loop. Version: 2.0 Author: Semper Fi Web Design Author 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. 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 -