My plugin, WP Coda Slider, uses a shortcode to get_posts and add them to the slider. If one of the posts contains shortcode the shortcode in that post will not work.
$my_wpcodaslider = new wpcodaslider();
class wpcodaslider{
var $shortcode_name = 'wpcodaslider';
var $pattern = '<!-- wpcodaslider -->';
var $posts_content = '';
function wpcodaslider() {
add_shortcode( $this->shortcode_name, array( &$this, 'shortcode' ) );
add_action( 'the_posts', array( &$this, 'wpcodaslider_scripts' ) );
}
// insert the shortcode in any page ie: [wpcodaslider id=slidername cat=4 show=3] will show first three post in category with id of 4
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 = '
<div class="coda-slider-wrapper">
<div class="coda-slider preload" id="'. $id .'">';
$posts = get_posts('post_type=post&order=desc&cat= '. $cat . '&numberposts= ' . $show . '');
foreach($posts as $post){
$o.=
'<div class="panel" id="post-' . $post->ID . '">
<div class="panel-wrapper">
<h2 class="title">' . $post->post_title . '</h2>
' . $post->post_content . '
</div> <!-- .panel-wrapper -->
</div><!-- .panel #post-$id -->';
}
$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;
}
It also does another foreach loop to check for its shortcode before enqueing the scripts.
function wpcodaslider_scripts($posts) {
if (empty($posts)) return $posts;
$shortcode_found = false; // use this flag to see if styles and scripts need to be enqueued
foreach ($posts as $post): {
if (stripos($post->post_content, 'wpcodaslider')) {
$shortcode_found = true; //shortcode found so lets load the scripts
break;
}
}
if ($shortcode_found) {
//enqueue scripts
wp_enqueue_script('coda_slider', WP_PLUGIN_URL . '/wp-coda-slider/js/coda.slider.js',
array('jquery'));
//enqueue style sheet
wp_enqueue_style('coda_slider', WP_PLUGIN_URL . '/wp-coda-slider/css/coda-slider-2.0.css');
}
return $posts;
}
}
Any ideas on how I can get shortcodes within the posts to work? I have tested it with the [gallery] shortcode and a few others from various plugins.