我为Wordpress编写了一小段代码,它将显示滑块中最新的前4个帖子(Filament Group Responsive Carousel)。它工作,显示帖子和滑动等,但有4个滑块,每个滑块有4个帖子。我必须定位一些WP_Query()
错误的代码。这是我的代码:
<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>
所以我的问题是,我需要使用什么代码重新定位/更改/添加/删除它以显示一个带有4个最新帖子的滑块,而不是4个最近发布帖子的4个滑块?
答案 0 :(得分:0)
我的猜测是你将代码调用到循环中:
if(have_posts()) while(have_posts()): the_post();
//HERE IS YOUR CODE
endwhile;
您必须在此循环之前或之后移动代码或删除循环ex。:
//if(have_posts()) while(have_posts()): the_post();
//HERE IS YOUR CODE
//endwhile;
或
//HERE IS YOUR CODE
if(have_posts()) while(have_posts()): the_post();
endwhile;