阿里云服务器

我们在做wordpress企业网站的时候,常常需要调用置顶文章来作为幻灯片。

在编辑文章的时候,可以勾选置顶文章

wordpress置顶文章调用


调用代码如下:

<?php  
$sticky = get_option('sticky_posts');  
rsort( $sticky );  
$sticky = array_slice( $sticky, 0, 5);  
query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );  
if (have_posts()) :  
while (have_posts()) : the_post();  
?>  
这里是需要显示的内容  
<?php endwhile; endif; ?>

直接在模板需要显示的位置插入就可以了。

相关阅读:
  • wordpress编辑框不让span过滤的方法
  • wordpress搜索为空时仍然返回结果问题
  • wordpress注册页取消邮箱的方法
  • wordpress用户头像在线调用代码
  • wordpress自动隐藏email注册,直接用户名密码注册
  • wordpress设置游客只能访问指定页面的方法
  • wordpress列表分页显示404页面的解决办法
  • wordpress页面默认排序修改的方法
  • wordpress新版本5.4 “Adderley” 发布上线,更新多项功能
  • wordpress默认编辑器功能增加的方法