Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
WP Coda Slider: Coda Slider featured category slider with shortcodes
<?php //Header
Plugin Name: WP Coda Slider
Plugin URI:
Description: Coda Slider featured category slider with shortcodes
Author: c3mdigital, makesites
Author URI:
Version: 0.2.6
License: GPL v2 -
// 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){
'<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 -->';
</div><!-- .coda-slider .preload -->
</div><!-- coda-slider-wrapper -->
<script type="text/javascript">
$().ready(function() {
$(\'#'. $id .'\').codaSlider({' . $args .'});
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 ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.