Using query_posts within a shortcode
-
[Apologies if in the wrong section and sorry if this is a really stupid question]
I’ve defined a custom post type. The featured images of this custom post type are used as a carousel. That all works fine and using cycle.js with the following code the carousel works.
<div class="carousel"> <?php $temp_query = clone($wp_query); ?> <?php query_posts('post_type=carousel&showposts=10'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="slide"><li> <?php if(has_post_thumbnail()) { the_post_thumbnail('featured_image'); } else { echo '<img width="460" height="280" src="image/placeholder.jpg" class="attachment-featured_image wp-post-image">'; } ?></li> </div><!-- Closing the class slide --> <?php endwhile; endif; ?> <?php wp_reset_query(); ?> </div>
I’ve been trying to work out a way to insert the above code into a short-code so that I can type [carousel] anywhere on the site and the carousel as defined above will appear rather than having to hardcode it in to a page. I’ve used shortcodes before to define basic layout stuff using the return function but I can’t work out how I can introduce PHP tp them in this way.
I’d be really grateful for any help anyone can offer.
- The topic ‘Using query_posts within a shortcode’ is closed to new replies.