public
Created

WP Coda Slider: Coda Slider featured category slider with shortcodes

  • Download Gist
wpcodaslider.php
PHP
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
<?php //Header
/*
Plugin Name: WP Coda Slider
Plugin URI: http://wp-performance.com/wp-coda-slider/
Description: Coda Slider featured category slider with shortcodes
Author: c3mdigital, makesites
Author URI: http://c3mdigital.com/
Version: 0.2.6
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
 
// You can use the short code or template tag if you need to parse posts that include a shortcode
// To use the template tag add (in PHP): if( function_exists('c3m_wpcodaslider') ) { c3m_wpcodaslider($id, $cat, $show, $args);}
// you must supply the variables when you add the function to your template. Example: c3m_codaslider('myslider', '81', '4', 'dynamicArrows:false');
// this would add a slider with the id of myslider and show 4 posts from category 81 with dynamic arrows set to false.
// all the variables must be present and in the same order.
 
 
// initiate the wpcodaslider class, containing the bulk of the plugin logic
$my_wpcodaslider = new wpcodaslider();
 
// load the JavaScript dependencies
add_action ('init', 'c3m_coda_scripts');
 
// Main plugin class
class wpcodaslider{
 
var $shortcode_name = 'wpcodaslider';
var $pattern = '<!-- wpcodaslider -->';
var $posts_content = '';
 
function wpcodaslider() {
add_shortcode( $this->shortcode_name, array( &$this, 'shortcode' ) );
return $this;
}
 
// insert the shortcode in any page ie: [wpcodaslider id=slidername cat=4 show=3] will show first three post in category with id $
function shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'cat' => null,
'id' => null,
'show' => null,
'args' => null
), $atts ) );
 
//Make sure there is a query and name
if (! $cat || ! $id)
return 'Could not load slider. Mallformed shortcode.';
 
$o = $this->markup( $id, $cat, $show, $args );
return $o;
}
 
// the function that is used by both the shortcode and the php method to create the markup
function markup( $id, $cat, $show, $args ){
// form the query
$query = array(
'post_type' => 'post',
'cat' => $cat,
'posts_per_page' => $show
);
// get the posts
$posts = get_posts( $query);
 
// start creating the markup
$o = '
<div class="coda-slider-wrapper">
<div class="coda-slider preload" id="'. $id .'">';
 
 
foreach($posts as $post){
 
$o.=
'<div class="panel" id="post-' . $post->ID . '">
<div class="panel-wrapper">
<h2 class="title">' . $post->post_title . '</h2>
' . apply_filters('the_content', $post->post_content) . '
</div> <!-- .panel-wrapper -->
</div><!-- .panel -->';
}
 
 
$o.='
</div><!-- .coda-slider .preload -->
</div><!-- coda-slider-wrapper -->
<script type="text/javascript">
jQuery(document).ready(function($){
$().ready(function() {
$(\'#'. $id .'\').codaSlider({' . $args .'});
});
});
</script>';
 
return $o;
 
}
}
 
// Helper Functions
 
// - Template tag method
function c3m_wpcodaslider($id, $cat, $show, $args) {
global $my_wpcodaslider;
echo $my_wpcodaslider->markup( $id, $cat, $show, $args );
 
return $id;
return $cat;
return $show;
return $args;
 
}
 
// - JavaScipt loader
function c3m_coda_scripts() {
wp_enqueue_script('coda_slider', WP_PLUGIN_URL . '/wp-coda-slider/js/coda.slider.js', array( 'jquery' ));
wp_enqueue_style('coda_slider_css', WP_PLUGIN_URL . '/wp-coda-slider/css/coda-slider-2.0.1.css');
wp_localize_script( 'coda_slider', 'Plugin_Url', array( 'plugin_url' => WP_PLUGIN_URL ) );
}
 
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.