完全公開,我是一個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