我有特定的类别,在哪些方面我有很多帖子。每个职位都从2019年10月21日开始。
我有以下代码以正确的顺序显示帖子:
class GoroskopController
{
static function get_data($parent_id, $number, $heading, $heading_color = \'dark\')
{
$loop = new \\WP_Query(GoroskopModule::loop_args($parent_id, $number));
if ($loop->have_posts()) :
echo \'<div class="goroskop-block mb30">\';
echo \'<div class="block-heading-color-small -\' . $heading_color . \' font-sans">\' . $heading . \'</div>\';
while ($loop->have_posts()) : $loop->the_post();
$this_date = self::this_gor(get_the_title());
include "templates/block.php";
endwhile;
wp_reset_query();
echo ($parent_id == 156) ? \'<div class="view-more font-sans"><a href="\' . get_category_link($parent_id) . \'">\' . esc_html__(\'Смотреть все\', \'grimple_core\') . \'</a></div>\' : \'\';
echo \'</div>\';
endif;
}
static function now_date()
{
$m = [
\'january\' => \'01\',
\'february\' => \'02\',
\'march\' => \'03\',
\'april\' => \'04\',
\'may\' => \'05\',
\'june\' => \'06\',
\'jule\' => \'07\',
\'august\' => \'08\',
\'september\' => \'09\',
\'october\' => \'10\',
\'november\' => \'11\',
\'december\' => \'12\'
];
return $m;
}
static function this_gor($title)
{
$gor_date = explode(\' \', $title);
$m = self::now_date();
$this_date = date(\'d.m.Y\');
$day = (mb_strlen($gor_date[0],\'UTF-8\') == 1) ? \'0\' . $gor_date[0] : $gor_date[0];
$month = $gor_date[1];
$year = $gor_date[2];
foreach ($m as $key => $value) {
if ($month == $key)
$month = $value;
}
$sep = \'.\';
$gor_out_date = $day . $sep . $month . $sep . $year;
$this_gor = ($this_date == $gor_out_date) ? true : \'\';
return $this_gor;
}
}
现在我只需要显示实际日期后的7篇帖子。
我试过这个
class GoroskopModule
{
static function loop_args($parent_id, $number)
{
$args = [
\'cat\' => $parent_id,
\'showposts\' => \'7\',
\'orderby\' => \'ID\',
\'order\' => \'asc\',
\'date_query\' => array(\'after\' => date(\'d.m.Y\', strtotime(\'-2 days\')) )
];
return $args;
}
}
但它不起作用,因为我有很多帖子是在同一天发表的。
我需要显示从第一个代码中计算的实际日期的7个帖子。泰