WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have written a small piece of code for Wordpress that will show the most recent top 4 posts in a slider (the Filament Group Responsive Carousel). It works, displaying the posts and sliding them etc, but there are 4 sliders, each with the 4 posts in them. I must have positioned some of the code with WP_Query() wrong. Here is my code:

<div class="carousel slider carousel-slide" data-transition="slide" data-autoplay="" data-interval="5000" data-paginate="true">
        $topNews = new WP_Query();
        while ($topNews->have_posts()) : $topNews->the_post(); ?>
            <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <header class="entry-header">
                    <?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                } ?>
                    <h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'android_and_tea' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
        <?php endwhile; ?>

So my question is, what code do I need to reposition/change/add/remove to get it to display one slider with the 4 most recent posts, instead of 4 sliders with the 4 most recent posts?

share|improve this question
Why do you need slider to show all in one box? I think you should move the while loop within the div id="post". Because, according to the plugin site, it creates a slide for each div inside the <div class="carousel" – mesvil7 Feb 15 '13 at 22:50
Hi, sorry for the delay in replying. Doing this basically makes the slider not work, as there is only one div created, and then 4 <header class="entry-content"> inside that. The slider images just pile on top of each, and 4 sliders are still generated. Thanks for trying :) – Tom Oakley Feb 19 '13 at 18:46

You should use posts_per_page=4 instead of showposts=4.

Reference: WP_Query Pagination Parameters

share|improve this answer
This didn't have any effect. Sorry, thanks for trying :) – Tom Oakley Feb 19 '13 at 18:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.