[英]Wordpress List with unpublished posts
I have 1 ul-list to display the posts already published and those that'll come in different styles. 我有1个ul列表来显示已经发布的帖子和那些会有不同风格的帖子。 Therefore I already have the posts set to a scheduled date in future to be published on wordpress (status: future)
因此,我已将帖子设置为将来的预定日期,以便在wordpress上发布(状态:将来)
This is what I am using: 这就是我正在使用的:
<ul>
// Here come the already published posts - this one works
<li class="bereits">Bereits erschienen</li>
<?php
if ( get_post_status ( $ID ) == 'publish' ) {
$args=array( 'posts_per_page'=>9, 'offset'=> 0, 'category' => '','orderby'=> 'post_date','order'=> 'ASC', );
$seiten = get_posts( $args );
foreach ( $seiten as $post ) : setup_postdata( $post ); ?>
<li class="aktiv">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
// And here shall come the future posts - doesn't work
<?php endforeach; wp_reset_postdata();
} else { ?>
<li class="nochnicht">Noch nicht erschienen</li>
<?php
$args_inaktiv=array( 'posts_per_page'=>9, 'offset'=> 0, 'category' => '','orderby'=> 'post_date','order'=> 'ASC', );
$seiten_inaktiv = get_posts( $args_inaktiv );
foreach ( $seiten_inaktiv as $post ) : setup_postdata( $post ); ?>
<li class="inaktiv">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; wp_reset_postdata();
} ?>
</ul>
The posts that are already published do get displayed nicely, but the futurous ones not. 已经发布的帖子确实很好地展示了,但未来的帖子没有。 Do I need to edit a setting on wordpress, or is my code wrong?
我需要在wordpress上编辑设置,还是我的代码错了?
Thanks so much 非常感谢
The default setting for the post status in the get_posts() function is 'publish'. get_posts()函数中post状态的默认设置是“publish”。 You can set this to 'future' if you only want future posts, or to 'publish, future' if you want both:
如果您只想要将来的帖子,可以将此设置为“future”,如果您想要两者,则可以将其设置为“publish,future”:
$args=array('posts_per_page'=>9, 'offset'=> 0, 'category' => '','orderby'=> 'post_date','order'=> 'ASC', 'post_status' => 'publish,future' );
For more info, check this and this one :) 有关更多信息,请检查此和这一个 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.