2014-09-04 103 views
0

我需要在頁面上的所有帖子列表中顯示未來的帖子。wordpress和將來的帖子

我的代碼

$args = array('posts_per_page' => 10, 
       'category' => $category->cat_ID); 
          ?> 

<?php $posts = get_posts($args); ?> 

什麼樣的參數,我可以寫一個展示未來的文章類別的所有訊息?

而且它在我的檔案頁面的代碼,我應該從類別

<?php if (have_posts()) : ?> 
         <?php while (have_posts()) : the_post(); ?> 
         <?php endwhile; ?> 
<?php endif; ?> 

該解決方案桅杆顯示未來和過去的職位顯示職位列表過

回答

1

,則應指定post_statuspublishfuture例如:$args,例如:

$args = array(
    'posts_per_page' => 10, 
    'category' => $category->cat_ID, 
    'post_status' => array(
     'publish', 
     'future' 
    ) 
); 

要獲得與這些帖子指定參數時,使用(例如):

$posts = get_posts($args); 

要顯示這些文章,使用(例如):

foreach($posts as $p) { 

    // display the post title 
    echo '<h2>' . apply_filters('the_title', $p->post_title) . '</h2>'; 

    // display the post date 
    echo '<h4>' . date('F jS, Y', strtotime($p->post_date)) . '</h4>'; 

    // display an excerpt of the post 
    echo wp_trim_excerpt($p->post_content); 
} 

一種替代方法是使用query_posts/WP_Query得到這些職位。在這種情況下,要顯示帖子,你可以使用一個循環,類似於你的問題。這樣的例子可以在這裏看到:http://codex.wordpress.org/Class_Reference/WP_Query#Standard_Loop

+0

thanx。那很好。有關任何情況的任何主張? – waldemar 2014-09-04 07:37:22

+0

我已經編輯了上面的答案,向您展示了一些用於實現此目的的示例代碼。 – 2014-09-04 07:43:16

+0

在IE中,如果我嘗試打開sheduled文章,我得到404錯誤。在其他瀏覽器中都可以 – waldemar 2014-09-04 17:42:00