【发布时间】:2011-01-17 21:51:37
【问题描述】:
我在 wordpress 中以正确的顺序显示事件时遇到问题。我认为问题在于 wordpress 将日期视为字符串并按天排序,因为它是英国日期格式。
目标是显示未来事件列表,最新事件位于列表顶部。但我必须使用 dd/mm/yyyy 的英国日期格式。
我需要回到绘图板上还是有办法转换日期以达到我需要的结果?
提前致谢:)
<ul>
<?php // Get today's date in the right format
$todaysDate = date('d/m/Y');?>
<?php query_posts('showposts=50&category_name=Training&meta_key=date&meta_compare=>=&meta_value=' . $todaysDate . '&orderby=meta_value&order=ASC'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<h3><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h3>
<?php $getDate = get_post_meta($post->ID, 'date', TRUE);
$dateArray = explode('/', $getDate); ?>
<?php if($getDate != '') { ?>
<div class="coursedate rounded"><?php echo date('d F Y', mktime(0, 0, 0, $dateArray[1], $dateArray[0], $dateArray[2])); ?></div>
<?php } ?>
<p><?php get_clean_excerpt(140, get_the_content()); ?>...</p>
<p><strong><a class="link" href="<?php the_permalink(); ?>">For further details and booking click here</a></strong></p>
</li>
<?php endwhile; ?>
<?php else : ?>
<li>Sorry, no upcoming events!</li>
<?php endif; ?>
【问题讨论】:
标签: php string events wordpress date