【发布时间】:2017-05-11 07:34:53
【问题描述】:
我有以下代码按标题对帖子进行排序。请参阅随附的屏幕截图。
这就是我现在得到的
我想要的是将帖子组合在一起,即日期为 12 月的帖子应低于 12 月,而 11 月的帖子应低于 11 月,依此类推。附上两张图片。
我需要对下面的代码进行一些调整。
<div class="margin-top" style="margin-top: 20px;">
<?php if ( have_posts() ) : ?>
<div class="articles-list">
<?php do_action( 'presscore_before_loop' ); ?>
<?php update_post_thumbnail_cache(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
$start=0;
$venue = basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if (isset($venue) && !empty($venue)) {
global $post;
$venue_a = get_term_by('slug',$venue, 'venues');
for($i=0;$i<10;$i++){
$key = get_post_meta($post->ID,'sub_seminars_'.$i.'_venue',true);
if($venue_a->name == $key ){
$ref = get_post_meta($post->ID,'sub_seminars_'.$i.'_ref',true);
$ven_label = get_post_meta($post->ID,'sub_seminars_'.$i.'_venue',true);
$start_date = get_post_meta($post->ID,'sub_seminars_'.$i.'_start_date',true);
$end_date = get_post_meta($post->ID,'sub_seminars_'.$i.'_end_date',true);
$fees = get_post_meta($post->ID,'sub_seminars_'.$i.'_fees',true);
$start =1;
break;
}
}
}
?>
<table class="gry-bkgrnd-sec" style=" border-collapse: collapse; width: 100%;">
<tbody>
<?php if( have_rows('sub_seminars') ): ?>
<?php while ( have_rows('sub_seminars') ) : the_row();
?>
<tr style="background-color: #50619a">
<td style="width: 100px; color: #fff;">Reference</td>
<td style="width: 400px; color: #fff;">Title</td>
<td style="width: 200px; color: #fff;">Dates</td>
<td style="width: 100px; color: #fff;">Venue</td>
<td style="width: 100px; color: #fff;">Fees</td>
</tr>
<tr>
<td style="width: 200px;"><?php the_sub_field('ref'); ?></td>
<td style="width: 400px;">
<a style=" color: #044970;" href="<?php the_permalink(); ?>" title="<?php echo the_title_attribute( 'echo=0' ); ?>" rel="bookmark">
<?php the_title(); ?></a><?php if (get_field('seminar_sub_title')) : ?>
<a style=" color: #044970;" href="<?php the_permalink(); ?>" rel="bookmark">
<?php the_field('seminar_sub_title'); ?><?php endif; ?></a>
</td>
<td>
<?php
if(date("m", strtotime($start_date)) != date("m", strtotime($end_date)))
{
echo date("d M", strtotime($start_date)).' - '.date("d M", strtotime($end_date));
}
else
{
echo date("d", strtotime($start_date)).' - '.date("d M", strtotime($end_date));
}
?>
</td>
<td style="width: 45px;">
<?php echo $ven_label; ?>
</td>
<td style="width: 45px;">
<?php echo $fees; ?>
</td>
</tr>
<?php break; ?>
<?php endwhile; ?>
<?php endif; ?>
</tbody>
</table>
<?php endwhile; ?>
<?php do_action( 'presscore_after_loop' ); ?>
</div>
<?php dt_paginator(); ?>
<?php else : ?>
<?php get_template_part( 'no-results', 'blog' ); ?>
<?php endif; ?>
</div>
显示的场所是创建的自定义分类法
【问题讨论】:
标签: php wordpress sorting custom-taxonomy