[英]Wordpress, Recent Posts in Slider
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). 我已经为Wordpress写了一小段代码,它将显示滑块(Filament Group Responsive Carousel)中最近的前4个帖子。 It works, displaying the posts and sliding them etc, but there are 4 sliders, each with the 4 posts in them.
它可以正常工作,显示帖子并滑动它们,等等,但是有4个滑块,每个滑块中都包含4个帖子。 I must have positioned some of the code with
WP_Query()
wrong. 我一定用
WP_Query()
定位了一些代码错误。 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? 所以我的问题是,我需要重新定位/更改/添加/删除什么代码才能显示一个带有4个最新帖子的滑块,而不是显示四个带有4个最新帖子的滑块?
My guess is that you call your code into the loop ex.: 我的猜测是您将代码调用到循环ex中:
if(have_posts()) while(have_posts()): the_post();
//HERE IS YOUR CODE
endwhile;
You'll have to move your code before or after this loop or to remove the loop ex.: 您必须在此循环之前或之后移动代码,或删除ex循环:
//if(have_posts()) while(have_posts()): the_post();
//HERE IS YOUR CODE
//endwhile;
or 要么
//HERE IS YOUR CODE
if(have_posts()) while(have_posts()): the_post();
endwhile;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.