我们在做wordpress网站的时候,常常需要自定义文章类型来拓展网站的功能。但是自定义文章类型创建后有部分功能是缺失的,比如说置顶的功能。

这个时候我们需要用到插件:Sticky Custom Post Types

启用后在后台设置需要这个功能的自定义文章类型:

20160919112332.jpg

这样在自定义文章发布的时候就会出现置顶选项给我们勾选。

下面教大家显示自定义文章类型置顶文章的方法:

<?php
 $sticky = get_option('sticky_posts');
 query_posts( array('post__in' => $sticky,'showposts' => 4,'caller_get_posts' => 1,'post_type'=>'product' ) );?>

<?php while (have_posts()) : the_post(); ?>
<li class="ban_sm_1">
<div class="ban_sm_1 con" >
<a href="<?php%20the_permalink()%20?>"><img src="<?php%20$full_image_url%20=%20wp_get_attachment_image_src(%20get_post_thumbnail_id($post->ID),%20'full');%20echo%20$full_image_url[0];%20?>"  title="<?php the_title(); ?>"></a>
</div>
</li>
<?php endwhile; ?>

通过以上代码即可实现wordpress自定义文章类型置顶文章的显示。