Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按月份显示帖子(带月份标题)-Wordpress_Php_Wordpress - Fatal编程技术网

Php 按月份显示帖子(带月份标题)-Wordpress

Php 按月份显示帖子(带月份标题)-Wordpress,php,wordpress,Php,Wordpress,我想实现这样的目标,我不知道这是否可能,最好的方法是什么: 我查询帖子的方式如下: <div class="post"> <?php global $wp_query; query_posts( array('post_type' => array( 'lecturas-post' ),'showposts' => 15, 'paged'=>$paged, 'order' => 'DESC' ));?> <?php

我想实现这样的目标,我不知道这是否可能,最好的方法是什么:

我查询帖子的方式如下:

<div class="post">
    <?php global $wp_query;
    query_posts( array('post_type' => array( 'lecturas-post' ),'showposts' => 15, 'paged'=>$paged, 'order' => 'DESC' ));?>
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
        <div><?php the_title() ?></a>
    <?php endwhile; // end of the loop. ?>
</div>

试试这个,我希望这对你有用

$args = array('posts_per_page' => -1, 'orderby' => 'date' );

$myQuery = new WP_Query($args);

$date = '';

if ( $myQuery->have_posts() ) : while ( $myQuery->have_posts() ) : $myQuery->the_post();

if ( $date != get_the_date() ) {
    echo $date;
    echo '<hr />';
    $date = get_the_date();
}

the_title(); // or whatever you want here.
echo '<br />';

endwhile; endif;
wp_reset_postdata();
$args=array('posts_per_page'=>-1,'orderby'=>'date');
$myQuery=新的WP\u查询($args);
$date='';
如果($myQuery->have_posts()):而($myQuery->have_posts()):$myQuery->the_post();
如果($date!=获取日期(){
echo$日期;
回声“
”; $date=获取日期(); } _title();//或者随便你想要什么。 回声“
”; 结束时;endif; wp_reset_postdata();
有关此查询的更多信息,请单击此处:

我从这里找到了答案。

请给出答案,希望这对您有所帮助:

$args = array(
            'post_type' => 'lecturas-post',
            'numberposts' => 15,
            'orderby' => 'post_date',
            'order' => 'DESC',
        );

$posts = wp_get_recent_posts( $args );
$collection = array();

foreach ( $posts as $lectura ){
    $index = date( 'Y-m', strtotime($lectura['post_date']) );
    $collection[ $index ][] = $lectura;
}
$collection现在每月包含您的帖子,您可以轻松地循环浏览它们

$args = array(
            'post_type' => 'lecturas-post',
            'numberposts' => 15,
            'orderby' => 'post_date',
            'order' => 'DESC',
        );

$posts = wp_get_recent_posts( $args );
$collection = array();

foreach ( $posts as $lectura ){
    $index = date( 'Y-m', strtotime($lectura['post_date']) );
    $collection[ $index ][] = $lectura;
}