完全公开,我是一个PHP noob。 我正在尝试为我的Wordpress网站构建页面模板。这个想法是从今天开始显示每一篇文章,并排除所有其他文章。似乎无法在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 – Mickey
我假设你是指阅读设置。它不会让我使用任何小于0. –
然后使其为零,你面临的概率实际上是分页 – Mickey