[教程] 获取WordPress当日发布的文章

查看: 338|回复: 0
wpocn 发表于 2023-2-28 13:34:22
获取WordPress当日发布的文章。
  1. <?php
  2.         $today = getdate();
  3.         $args = array(
  4.                 'posts_per_page' => '20', // 篇数
  5.                 'ignore_sticky_posts' => true,
  6.                 'date_query' => array(
  7.                         array(
  8.                                 'year'  => $today['year'],
  9.                                 'month' => $today['mon'],
  10.                                 'day'   => $today['mday'],
  11.                         ),
  12.                 ),
  13.         );

  14.         $query = new WP_Query( $args );
  15. ?>
  16. <ul>
  17.         <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();?>
  18.                 <li>
  19.                         <?php the_title( sprintf( '<a class="title" href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a>' ); ?>
  20.                 </li>
  21.         <?php endwhile;?>
  22.                 <?php wp_reset_postdata(); ?>
  23.         <?php else : ?>
  24.                 <li>
  25.                         暂无更新
  26.                 </li>
  27.         <?php endif;?>
  28. </ul>
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于本站联系我们FAQ友情链接免责声明生存法则

Build with for "make" Copyright © 2020-2022. Powered by Discuz! GMT+8, 2024-4-26 18:55

快速回复 返回顶部 返回列表