php 按年份,月份获取帖子
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 按年份,月份获取帖子相关的知识,希望对你有一定的参考价值。
https://stackoverflow.com/questions/12898297/wordpress-how-to-return-just-current-month-posts-on-archive-php
https://developer.wordpress.org/files/2014/10/wp-hierarchy.png
https://wordpress.stackexchange.com/questions/176141/display-posts-by-month
<?php
// get year and month from query url
$link = $_SERVER["REQUEST_URI"];
if(substr($link, -1) == '/') {
$link = substr($link, 0, -1);
}
$date_array = explode('/',$link);
$args = [
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'order' => 'date',
'year' => $date_array[1],
'monthnum' => $date_array[2]
];
$posts = new WP_Query( $args );
if( $posts->have_posts() ) :
while( $posts->have_posts() ) :
$posts->the_post();
echo get_the_permalink() ;
endwhile;
endif;
以上是关于php 按年份,月份获取帖子的主要内容,如果未能解决你的问题,请参考以下文章