WordPress删除最近发布的帖子

时间:2015-01-15 02:04:31

标签: php wordpress

我希望我的代码能够删除第一个查询中显示的帖子,并在上面显示的帖子之后显示3个最近的帖子。

热门帖子:

<?php query_posts('posts_per_page=1'); if (have_posts()) : while (have_posts()) : the_post();?> 
<h2><?php the_title(); ?></h2>
<div class="news-feat-img">
<a href="<?php the_permalink(); ?>" ><?php the_post_thumbnail('indexsavedimage'); ?></a>
</div>
<?php the_excerpt(); ?> 
<?php endwhile; endif; wp_reset_query();?>

最近发布的帖子:

</a><div class="clearboth"></div>
<div class="borderline"></div>
<?php query_posts('posts_per_page=3'); if (have_posts()) : while (have_posts()) : the_post();?> 
<!-- Older news articles -->
<div class="news-posts">
<div class="news-thumb-wrap">
<div class="news-thumb">
<a href="<?php the_permalink(); ?>" ><?php the_post_thumbnail('newsimages'); ?></a>
</div>
</div>
<!-- Truncate long titles to stop the layout from messing up! -->
<a class="title" href="<?php the_permalink(); ?>">
<strong><?php the_title(); ?></strong>
</a>
<div class="clearboth"></div>
<?php the_excerpt(); ?> 
<div class="news-action">
<span class="label"><?php the_category( ', ' ); ?></span>
<a href="<?php the_permalink(); ?>" ><span class="label"><i class="icon-share icon-white"></i>    </span></a>
</div>
</div>
<?php endwhile; endif; wp_reset_query();?>

enter image description here

1 个答案:

答案 0 :(得分:0)

首先,如果您还没准备好,请阅读WP_Query - http://codex.wordpress.org/Class_Reference/WP_Query

一个重要的论点是posts_per_page

<?php
$posts = WP_Query(array(
    'posts_per_page' => 4,
    # ...
));

# From WordPress's example, modified of course
$i = 0;
if ( $the_query->have_posts() ) {
        while ( $the_query->have_posts() ) {
                $the_query->the_post();

                if(!$i)
                {
                    // First style
                    echo "Some HTML for the first post,<br/>";
                }
                else
                {
                    // Code for second style
                    echo "HTML for the rest!";
                }

                $i++;
        }
} else {
        // no posts found
}
编辑:对不起,mismisread?大声笑。你去吧