web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

wordpress首页(列表页)如何显示指定时间内的文章

566 ℃
     

功能介绍:不想在首页/列表页显示最新的文章,需要显示指定时间内的文章。

解决方法如下:

query_posts($query_string);上面显示以下代码:

只显示<=前天发布的文章

if ( have_posts() ) {
  function filter_where($where = '') {
    $where .= " AND post_date <= '" . date('Y-m-d', strtotime('-1 days')) . "'"; 
    return $where;
  }
  add_filter('posts_where', 'filter_where');

  query_posts($query_string);
  ...
  ...
}

显示30天内发布的文章

if ( have_posts() ) {
  function filter_where($where = '') {
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";  
    return $where;
  }
  add_filter('posts_where', 'filter_where');

  query_posts($query_string);
  ...
  ...
}

只显示过去30天-60天内发布的文章

if ( have_posts() ) {
  function filter_where($where = '') {
    $where .= " AND post_date >= '" . date('Y-m-d', strtotime('-60 days')) . "'" . " AND post_date <= '" . date('Y-m-d', strtotime('-30 days')) . "'";  
    return $where;
  }
  add_filter('posts_where', 'filter_where');

  query_posts($query_string);
  ...
  ...
}

只显示某个时间段内发布的文章

if ( have_posts() ) {
  function filter_where($where = '') {
    $where .= " AND post_date >= '2022-03-01' AND post_date < '2023-03-01'";  
    return $where;
  }
  add_filter('posts_where', 'filter_where');

  query_posts($query_string);
  ...
  ...
}

wordpress做时间列表,比如2024年1月文章列表

wordpress利用mysql获取指定分类下的文章

WordPress如何重置admin密码

wordpress建站如何利用mysql语法批量插入文章

WordPress教程如何自动删除文章中图片宽高样式

标签: wordpress建站, wordpress技巧, 调用文章

上面是“wordpress首页(列表页)如何显示指定时间内的文章”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_3461.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > wordpress
本文共计998个字,预计阅读时长7分钟
生活小工具,收录了80多款小工具
上一篇: 程序员正能量文案:乐观积极的治愈系文案,朋友圈满满向上动力句子
下一篇: Lunar组件如何利用I18n实现多语言功能
x 打工人ai神器