我这里有一个查询,显示它是否匹配当前发布的月份和年份。第二个代码需要与第一个代码相反,第一个代码显示除与当前月份和年份匹配的代码外的所有帖子。
// CURRENT MONTH AND YEAR ONLY
<?php
$current_year = date(\'Y\', current_time(\'timestamp\'));
$current_month = date(\'m\', current_time(\'timestamp\'));
if ( have_posts() ) { while ( have_posts() ) { the_post(); }}
$args = array(\'post_type\' => \'page\', \'post_status\' => \'publish\', \'posts_per_page\' => 12, \'post_parent\' => 11120, \'orderby\'=> \'menu_order\', \'year\' => $current_year, \'monthnum\' => $current_month, \'order\' => \'DESC\');
$query = new WP_Query($args);
$catNull = get_template_directory_uri();
while ($query->have_posts()) {
$query->the_post(); ?>
<li class="active MonthTreats slide">
<div class="MonthHeader">
<h1><?php the_title(); ?></h1>
</div>
<div class="Content">
<div class="MonthContent">
<div class="container">
<p class="Status">NOW AVAILABLE</p>
<?php echo c2c_get_custom(\'Short Description\', $before=\'<h2>\', $after=\'</h2>\'); ?>
<?php the_content(); ?>
</div>
</div>
</div>
</li>
<?php
}
wp_reset_postdata();?>
// ALL POST EXCEPT CURRENT MONTH AND YEAR
<?php
if ( have_posts() ) { while ( have_posts() ) { the_post(); }}
$args = array(\'post_type\' => \'page\', \'post_status\' => \'publish, future\', \'posts_per_page\' => 12, \'post_parent\' => 11120, \'orderby\'=> \'menu_order\', \'order\' => \'asc\');
$query = new WP_Query($args);
$catNull = get_template_directory_uri();
while ($query->have_posts()) {
$query->the_post(); ?>
<li class="MonthTreats slide">
<div class="MonthHeader">
<h1><?php the_title(); ?></h1>
</div>
<div class="Content">
<div class="MonthContent">
<div class="container">
<p class="Status">NOW AVAILABLE</p>
<?php echo c2c_get_custom(\'Short Description\', $before=\'<h2>\', $after=\'</h2>\'); ?>
<?php the_content(); ?>
</div>
</div>
</div>
</li>
<?php
}
wp_reset_postdata();?>
</ul>