我试图显示当前月份的帖子,将粘性帖子保留在最顶层。
这是我的代码:
$today = getdate();
$args = array(
'monthnum' => $today["mon"],
'year' => $today["year"]
);
query_posts( $args );
while (have_posts() ) : the_post();
// some code...
endwhile;
结果是按时间顺序排列的帖子列表,但没有将粘贴帖子放在顶部。
我该如何解决?
答案 0 :(得分:1)
这是我的芯片,我在工作时没有经过测试,但如果你有任何问题我会告诉我,当我得到的时候我会测试并修复家。
<?php
/*--- Create a sticky loop ---*/
$sticky = get_option( 'sticky_posts' );
// These args will return only one sticky post
$stickyArgs = array(
'post__in' => $sticky,
// remove these to return all sticky posts
'posts_per_page' => 1,
'ignore_sticky_posts' => 1
);
// create your query
$stickyQuery = new WP_Query( $stickyArgs );
if ( isset($sticky[0]) ) {
//
// Post Content here
//
}
wp_reset_query();
// I haven't comented this section because it was your code
$today = getdate();
$todayArgs = array(
'monthnum' => $today["mon"],
'year' => $today["year"]
);
$todayQuery = new WP_Query( $todayArgs );
if ($todayQuery->have_posts()) {
while($todayQuery->have_posts()) {
$todayQuery->the_post();
//
// Post Content here
//
} // end while
} // end if
// reset the query again.. this is optional, I don't know what else is on your page.
wp_reset_query();
?>
让我知道你是如何进行的:)