このカスタムページの読み込みには少なくとも40秒かかります。他のページは3秒以内に読み込まれます。今日のニュースのように、今日だけの投稿をフロントページに表示したいと思います。コードの何が問題になっていますか?
<div class="row">
<?php list($latest_post) = get_posts( array( "posts_per_page"=>1 ));
$date = substr($latest_post->post_date, 0,10); // Show only news from this date
?>
<div class="medium-8 large-8 columns" role="main">
<?php
unset($counter);
/*these are the category ID */
$cats = array(49, 10, 50);
#$cats = get_categories();
foreach($cats AS $cat):
$posts = get_posts( array( "posts_per_page"=>100, "category"=>$cat ));
$catname = get_the_category_by_ID($cat);
$foundPost = false;
foreach($posts AS $post):
$postdate = substr($post->post_date, 0,10);
if($postdate!=$date) break;
if(!$foundPost) { // Print title if at least one post is found
$foundPost = true;
if ( in_category('Category Text') ) {
echo '<div class="redBackground">'.$catname.'</div>';
}
}
?>
<?php
the_post();
?>
<div class="row">
<div class="small-2 columns"><?php the_post_thumbnail();?></div>
<div class="small-10 columns"> <div class="fontSize"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<div class="contentTag"><?php the_tags(''); ?></div>
<div class="contentText"> <span style="color: #000"><?php echo people_Content(150); ?></span>
</div></div>
</div>
<?php
?>
<?php
endforeach;
endforeach; ?>
</div>
</div>
より選択的なクエリを実行し、現在の日の投稿のみを選択する必要があります。以下は、必要な場所に到達するためのループを含むクエリです。
//Get todays date
$today = getdate();
/*these are the category ID */
$cats = array(49, 10, 50);
//setup arguments for query including today's date
$args = array(
'category__in' => $cats,
'date_query' => array(
'year' => $today['year'],
'month' => $today['mon'],
'day' => $today['mday'],
)
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// this is where you will print out the details of each post
}
} else {
//There were no posts for today.
}
// Restore original Post Data (you may not need this but it can't hurt)
wp_reset_postdata();
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加