简体   繁体   English

我将如何更改此代码以仅在Wordpress中显示“粘帖”?

[英]How would I alter this code in order to show only “Sticky Posts” in Wordpress?

Basically i'm working on making my custom wordpress theme run on a grid style of posts in the top half of the homepage, however I would only like this code to show the sticky posts with a limited number of 5 posts, as opposed to a set number of non sticky posts? 基本上,我正在使我的自定义wordpress主题在首页的上半部分以网格形式发布,但是我只希望此代码显示有限数量的5个帖子,而不是设置非粘性帖子的数量?

I'm not the best with PHP, so any help would be great! 我不是使用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(); 
?>

You should really be using WP_query for this type of function. 您实际上应该将WP_query用于此类函数。 Use this type of code: 使用以下类型的代码:

<?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 );
?>

Hope this helps :) 希望这可以帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM