我们在做 wordpress企业网站 的时候,常常需要调用置顶文章来作为幻灯片。 在编辑文章的时候,可以勾选置顶文章 调用代码如下: ?php$sticky=get_option(sticky_posts);rsort($sticky);$sticky=array_s
我们在做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; ?>
直接在模板需要显示的位置插入就可以了。
发表评论