基本上我正在努力让我的自定义wordpress主题在主页的上半部分的网格样式上运行,但我只希望此代码显示有限数量的5个帖子的粘性帖子,如反对一定数量的非粘性帖子?
我不是最好的PHP,所以任何帮助都会很棒!
<?php
$counter = 1; //start counter
$grids = 2; //Grids per row
global $query_string; //Need this to make pagination work
/*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
query_posts($query_string . '&caller_get_posts=1&posts_per_page=12');
if(have_posts()) : while(have_posts()) : the_post();
?>
答案 0 :(得分:1)
你应该真正使用WP_query这种类型的功能。使用这种类型的代码:
<?php
$args = array(
'posts_per_page' => 1, <= This will display how many posts!!
'post__in' => get_option( 'sticky_posts' ), <= Stickies Posts!!
'ignore_sticky_posts' => 1
);
$query = new WP_Query( $args );
?>
希望这会有所帮助:)