我们在网站分类中常常需要设置置顶文章,而且与正常的文章有不一样的样式。

通过下面的调用代码就可以实现:


<?php if (have_posts()) : ?> 
 
    <?php while (have_posts()) : the_post();  
        if (is_sticky()): 
            global $more;    // 设置全局变量$more 
            $more = 1; 
    ?> 

<div class="col-md-12 blog_img lost">
<div class="blog_con">
<a href="<?php%20the_permalink()%20?>"><img src="<?php%20$large_image_url%20=%20wp_get_attachment_image_src(%20get_post_thumbnail_id($post->ID),%20'full');echo%20$large_image_url[0];?>" alt=" " class="img-responsive"></a>
							<div class="blog_info">
						 
								<h5><a href="<?php%20the_permalink()%20?>"><?php the_title(); ?></a></h5>
								<ul class="blog_list">
									<li><span class="fa fa-user" aria-hidden="true"></span><?php the_author_login(); ?><i>|</i></li>
									<li><span class="fa fa-heart" aria-hidden="true"></span><?php post_views(' ', ' 次'); ?></li>
								</ul>
								 
							</div>
						</div>
					</div>			
		
		
    <?php else: 
            global $more;   
            $more = 0; 
    ?> 
<div class="col-md-6 blog_img">
<div class="blog_con">
<a href="<?php%20the_permalink()%20?>"><img src="<?php%20$large_image_url%20=%20wp_get_attachment_image_src(%20get_post_thumbnail_id($post->ID),%20'full');echo%20$large_image_url[0];?>" alt=" " class="img-responsive"></a>
							<div class="blog_info">
						 
								<h5><a href="<?php%20the_permalink()%20?>"><?php the_title(); ?></a></h5>
								<ul class="blog_list">
									<li><span class="fa fa-user" aria-hidden="true"></span><?php the_author_login(); ?><i>|</i></li>
									<li><span class="fa fa-heart" aria-hidden="true"></span><?php post_views(' ', ' 次'); ?></li>
								</ul>
								 
							</div>
						</div>
					</div>	 
    <?php endif; ?> 
<?php    endwhile; ?> 

<?php else: ?> 
<h2>没有找到相应文章</h2> 
<?php endif; ?>

通过上面代码分别在对应位置插入置顶文章代码和正常文章代码就可以了。