欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

wordpress獲取置頂文章列表的方法

  發(fā)布時(shí)間:2014-02-26 16:44:33   作者:佚名   我要評(píng)論
在WordPress中,或許你希望調(diào)用設(shè)置好的指定文章列表,這一功能如何實(shí)現(xiàn)呢?下文就介紹實(shí)現(xiàn)方法,大家參考使用吧

首先,你需要了解query_posts函數(shù)。該函數(shù)的作用就是對(duì)文章進(jìn)行檢索、挑選、排序,在其后的LOOP循環(huán)中使用經(jīng)過(guò)挑選、排序的文章。例如:


復(fù)制代碼
代碼如下:

<?php
query_posts('posts_per_page=10&ignore_sticky_posts=1&orderby=rand');
while(have_posts()):the_post();
echo '<li>';the_title();echo '</li>';
endwhile;
wp_reset_query();

將隨機(jī)列出一條文章的標(biāo)題。至于query_posts的具體參數(shù),請(qǐng)參考開(kāi)發(fā)手冊(cè)。

接下來(lái),我們就是要通過(guò)對(duì)query_posts的參數(shù)進(jìn)行調(diào)整,挑選出置頂?shù)奈恼铝斜砹恕?/p>


復(fù)制代碼
代碼如下:

$query_post = array(
'posts_per_page' => 10,
'post__in' => get_option('sticky_posts'),
'caller_get_posts' => 1
);
query_posts($query_post);
?>
<ul style="display:none;">
<?php while(have_posts()):the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php
wp_reset_query();

參數(shù)用一個(gè)數(shù)組的形式放在$query_post中,關(guān)鍵的參數(shù)為'post__in' =>get_option('sticky_posts')和'caller_get_posts' => 0。

'post__in' => get_option('sticky_posts')確定了該LOOP調(diào)用的是置頂文章列表。'caller_get_posts'的作用是排除非指定性文章,即除了置頂文章之外,不顯示其他的文章。(不添加的情況下,如果置頂文章條目不足'posts_per_page'規(guī)定的值,會(huì)用最新文章替補(bǔ)完整。)

相關(guān)文章

最新評(píng)論