php技术博客
让天下没有搞不定的bug~

wordpress读取某个指定时间之前的文章

wordpress读取某个指定时间之前的文章,我这里是读取当前文章时间之前的文章。用before来限制时间即可。
    $post_num   =   8;
    $exclude_id =   $post->ID;
    //根据时间约束
    $date_query=array(
         array(
         'column' => 'post_date',
         'before' => date('Y-m-d H:i',strtotime($post->post_date)),  //在此文章发布时间之前,包括当天
         //'after'  => date('Y-m-d H:i',time()-3600*24*30)   //在此时间之后
         )
    );
    $posttags   =   get_the_tags();
    $i          = 0;
    if ($posttags) {
        $tags = '';
        foreach ($posttags as $tag) $tags.= $tag->term_id . ',';
        $args = array(
            'post_status'           =>  'publish',
            'tag__in'               =>  explode(',', $tags) ,
            'post__not_in'          =>  explode(',', $exclude_id) ,
            'ignore_sticky_posts'   =>  1,
            'orderby'               =>  'comment_date',
            'posts_per_page'        =>  $post_num,
            'date_query'            =>  $date_query,

        );
        query_posts($args);
        while (have_posts()) {
            the_post(); ?><div class="broke-product"><div class="pro-inner"><div class="broke-img" style="background:url(<?php
            uctheme_post_thumbnail_src(); ?>)no-repeat;background-size: 100% 100%;"><a href="<?php
            the_permalink(); ?>"></a></div><div class="broke-info"><a href="<?php
            the_permalink(); ?>"><h4><?php
            echo mb_strimwidth(get_the_title() , 0, 30, "..."); ?></h4><div class="broke-tips"><span class="broke_qa">¥</span><em><?php
            echo floatval(get_post_meta($post->ID, "quanhou_value", true)); ?></em><div class="broke_yjia">券后价</div></div><div class="broke_qquan"><span class="broke_quan">领券减:<i class="broke_huij"><?php
            echo floatval(get_post_meta($post->ID, 'youhui_value', true)); ?>元</i></span><div class="broke_lingquan"><?php
            echo get_post_meta($post->ID, "sale_value", true); ?>人购买</div></div></a></div></div></div><?php
            $exclude_id.= ',' . $post->ID;
            $i++;
        }
        wp_reset_query();
    }
赞(0)
未经允许不得转载:PHP技术博客 » wordpress读取某个指定时间之前的文章