Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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">
    <?php
        $topNews = new WP_Query();
        $topNews->query('showposts=4'); 
        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.
                        the_post_thumbnail('full');
                } ?>
                    <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>
                </header>
            </div>
        <?php endwhile; ?>
</div>

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

1 Answer 1

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

 
discard

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.