Php 我将如何修改此代码以仅显示“;"粘帖";用Wordpress?
基本上,我正在努力使我的自定义wordpress主题在主页上半部分的一个网格样式的帖子上运行,但是我只希望这段代码以有限数量的5篇帖子来显示粘性帖子,而不是固定数量的非粘性帖子 我不是PHP的高手,所以任何帮助都会很好Php 我将如何修改此代码以仅显示“;"粘帖";用Wordpress?,php,wordpress,loops,grid,themes,Php,Wordpress,Loops,Grid,Themes,基本上,我正在努力使我的自定义wordpress主题在主页上半部分的一个网格样式的帖子上运行,但是我只希望这段代码以有限数量的5篇帖子来显示粘性帖子,而不是固定数量的非粘性帖子 我不是PHP的高手,所以任何帮助都会很好 <?php $counter = 1; //start counter $grids = 2; //Grids per row global $query_string; //Need this to make pagination work /*Setting u
<?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();
?>
对于这种类型的函数,您确实应该使用WP\u查询。使用以下类型的代码:
<?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 );
?>
希望这有帮助:)哦,是的!WP_查询是一种更好的方法,不要忘记在查询后重置post:)一点问题也没有:)