简体   繁体   English

是否可以在 Wordpress 博客页面中显示即将发布的帖子?

[英]Is it possible to display upcoming posts in Wordpress blog page?

Is it possible to display upcoming posts in Wordpress 4+ blog page and how can I do that?是否可以在 Wordpress 4+ 博客页面中显示即将发布的帖子,我该怎么做? I was searching everywhere and no answer for this version of Wordpress.我到处搜索,但没有找到这个版本的 Wordpress 的答案。 Blog page only shows posts from the date before today and that's not what I want.博客页面只显示今天之前日期的帖子,这不是我想要的。 I want to show posts that's, let's say scheduled for 2 months in a future.我想显示的帖子是,假设计划在未来 2 个月内发布。

Use post_status=future with the standard Wordpress query_posts .post_status=future与标准 Wordpress query_posts See https://codex.wordpress.org/Post_Statushttps://codex.wordpress.org/Post_Status

This is a simple example loop for 10 posts with error "no posts" message, title and date:这是一个简单的示例循环,包含 10 个带有错误“无帖子”消息、标题和日期的帖子:

<?php query_posts('posts_per_page=10&post_status=future'); ?>

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

<h2><?php the_title(); ?></h2>

<span class="datetime"><?php the_time('j. F Y'); ?></span></p>

<?php endwhile; else: ?>

<p>No future events scheduled.</p>

<?php endif; ?>

This is probably more what you are looking for.这可能是您正在寻找的更多内容。 It's a function that includes future posts on date archives and single posts.这是一个功能,包括日期档案和单个帖子的未来帖子。 Put in the functions.php file of your theme:放入主题的functions.php文件:

if ( !is_admin() ) :
function __include_future( $query )
{
    if ( $query->is_date() || $query->is_single() )
        $GLOBALS[ 'wp_post_statuses' ][ 'future' ]->public = true;
}
add_filter( 'pre_get_posts', '__include_future' );
endif;

From https://wordpress.stackexchange.com/questions/16794/show-scheduled-posts-in-archive-page来自https://wordpress.stackexchange.com/questions/16794/show-scheduled-posts-in-archive-page

Essentially, it says, "If we're on a date archive, or viewing a single post, make future posts publicly visible."从本质上讲,它说,“如果我们在日期存档,或查看单个帖子,让未来的帖子公开可见。” As a result, WordPress behaves normally when you view archives for any given date, except now it also includes posts "from the future."因此,当您查看任何给定日期的档案时,WordPress 会正常运行,但现在它还包括“来自未来”的帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM