【发布时间】:2016-11-23 23:10:51
【问题描述】:
完全披露,我是 PHP 菜鸟。 我在尝试为我的 Wordpress 网站构建的页面模板时遇到问题。我们的想法是显示今天的每个帖子,并排除所有其他帖子。
有人帮我编写了一些代码,但我遇到了一个新问题 - 仅显示今天最旧的帖子!我测试了三个间隔几分钟的帖子,只有第一个出现。
任何帮助表示赞赏。
完整代码如下。
<?php
/**
* Template Name: Home Page
* The template for displaying all of today's posts on home page.
*
* This is the template that displays only today's posts.
* Please note that this is the WordPress construct of pages and that
* other "pages" on your WordPress site will use a different template.
*
* @package WordPress
* @subpackage Twenty_Fifteen
* @since Twenty Fifteen 1.0
*/
get_header(); ?>
<?php
$today = getdate();
$args = array(
'date_query' => array(
array(
'year' => $today['year'],
'month' => $today['mon'],
'day' => $today['mday'],
),
),
);
$query = new WP_Query( $args );
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
if ($query->have_posts() )
echo'<ul>';
while ( $query->have_posts() ) {
$query->the_post();
}
echo '</ul>';
// Include the page content template.
get_template_part( 'content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
/* Restore Post Data */
wp_reset_postdata();
else : // no posts found.
;
endif ;
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php get_footer(); ?>
【问题讨论】:
-
从管理员设置每页的帖子到 -1
-
我假设您的意思是阅读设置。它不允许我使用小于 0 的任何东西。
-
然后归零,你面临的问题其实是分页
-
哎呀,我的意思是小于 1。我的错。