簡體   English   中英

Wordpress列表與未發布的帖子

[英]Wordpress List with unpublished posts

我有1個ul列表來顯示已經發布的帖子和那些會有不同風格的帖子。 因此,我已將帖子設置為將來的預定日期,以便在wordpress上發布(狀態:將來)

這就是我正在使用的:

<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>

已經發布的帖子確實很好地展示了,但未來的帖子沒有。 我需要在wordpress上編輯設置,還是我的代碼錯了?

非常感謝

get_posts()函數中post狀態的默認設置是“publish”。 如果您只想要將來的帖子,可以將此設置為“future”,如果您想要兩者,則可以將其設置為“publish,future”:

$args=array('posts_per_page'=>9, 'offset'=> 0, 'category' => '','orderby'=> 'post_date','order'=> 'ASC', 'post_status' => 'publish,future' );

有關更多信息,請檢查這一個 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM