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?
You should use
posts_per_page=4
instead ofshowposts=4
.Reference:
WP_Query
Pagination Parameters