我试图在WordPress网站上创建日历显示。每天都会显示可用的活动清单。
目前我已将其设置为每个活动都是新的自定义帖子类型('活动')并在编辑页面上,使用“高级自定义”字段和复选框选项(字段名称&# 39;一天')你可以选择周二周一等。
我可以通过以下代码显示活动帖子上的日期(即“足球”和“游泳”等):
<?php
/*
* Conditional statement (Checkbox value is an array)
*/
if( in_array( 'tuesday', get_field('day') ) )
{ ?>
<?php the_title();?>
<?php } ?>
但我希望所有帖子都在正确的日期内显示在摘要/存档页面上 - 目前设置如下:
<div class="day-container">
<span class="day">Tu<span class="not-mobile">esday</span></span>
<ul>
<li class="swimming"> <div class="icon"> </div> Swimming</li>
<li class="fitness"> <div class="icon"> </div> Fitness</li>
<li class="walks"> <div class="icon"> </div> Health Walks</li>
</ul>
</div>
<div class="day-container">
<span class="day">Tu<span class="not-mobile">esday</span></span>
<ul>
<li class="swimming"> <div class="icon"> </div> Swimming</li>
<li class="fitness"> <div class="icon"> </div> Fitness</li>
<li class="walks"> <div class="icon"> </div> Health Walks</li>
</ul>
</div>
... etc
答案 0 :(得分:0)
所以经过一段时间的安排后我就设法了,如果有人遇到同样的问题,请参阅下面的答案!
<?php
$weekdays = array(
'monday' => 'Monday',
'tuesday' => 'Tuesday',
'wednesday' => 'Wednesday',
'thursday' => 'Thursday',
'friday' => 'Friday',
'saturday' => 'Saturday',
'sunday' => 'Sunday',
);
?>
<?php
foreach($weekdays as $day):
// args
$args = array(
'numberposts' => -1,
'post_type' => 'activity',
//'meta_key' => 'day',
//'meta_value' => $day
'meta_query' => array(
array(
'key' => 'day',
'value' => $day,
'compare' => 'LIKE'
)
)
);
// get results
$the_query = new WP_Query( $args );
// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<div class="day-container<?php echo strtolower(date('l')) == strtolower($day) ? ' active' : ''; ?>">
<span class="day"><?php echo substr($day,0,2); ?><span class="not-mobile"><?php echo substr($day,2); ?></span></span>
<ul>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li class="<?php echo strtolower(get_the_title()); ?>">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
<?php endif; ?>
<?php endforeach; ?>