wordpress自定义文章类型置顶文章显示
我们在做wordpress网站的时候,常常需要自定义文章类型来拓展网站的功能。但是自定义文章类型创建后有部分功能是缺失的,比如说置顶的功能。
这个时候我们需要用到插件:Sticky Custom Post Types
启用后在后台设置需要这个功能的自定义文章类型:
这样在自定义文章发布的时候就会出现置顶选项给我们勾选。
下面教大家显示自定义文章类型置顶文章的方法:
<?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 the_permalink() ?>"><img src="<?php $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); echo $full_image_url[0]; ?>" title="<?php the_title(); ?>"></a> </div> </li> <?php endwhile; ?>
通过以上代码即可实现wordpress自定义文章类型置顶文章的显示。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END