WordPress調用置頂文章代碼教程

WordPress調用置頂文章是常用的調用代碼,碼筆記分享WordPress調用置頂文章代碼:

WP調用置頂文章代碼

以下代碼爲調用5篇置頂文章:

<?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();?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
//碼筆記:調用置頂文章代碼

默認爲調用5篇置頂文章,您可以修改$sticky, 0, 5中的數字來自定義調用置頂文章數量。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章