我有一个有趣的问题,我正在努力解决。以下是我的情况:
我已经为“事件”创建了一个自定义帖子类型我目前唯一遇到的问题是显示特定分类术语的所有事件。
换句话说。。。除了每个事件列表之外,我还包括了自定义分类法(事件类别)中与事件相关的所有术语。
因此,这里的问题是,每个分类术语(正确地)显示为一个链接,但当您选择该术语时,相应的术语存档页面不会按事件日期/时间自定义字段对相应的结果排序,也不会排除早于今天日期的事件。
基于此页面:http://codex.wordpress.org/images/1/18/Template_Hierarchy.png
我发现,可以通过如下方式命名归档文件,为属于自定义分类法的所有术语创建自定义归档页面:
taxonomy-event\\u类别。php(其中“event\\u categories”)是我的自定义分类法的名称。
Soooooooo。。。。如上所述,我认为我唯一需要的解决方案是插入正确的代码来实现上述两个问题。
以下是我正在使用的代码,该代码用于按事件开始日期/时间正确组织显示我的事件列表,同时删除所有早于今天的事件。
<?php
//Get the metadata for each child page
global $custom_metabox_event_dates;
$meta1 = $custom_metabox_event_dates->the_meta();
$today = time();
$arrMonthNums = array("01" => "01", "02" => "02", "03" => "03", "04" => "04", "05" => "05", "06" => "06", "07" => "07", "08" => "08", "09" => "09", "10" => "10", "11" => "11", "12" => "12");
$arrMonthNames = array("01" => "JANUARY", "02" => "FEBRUARY", "03" => "MARCH", "04" => "APRIL", "05" => "MAY", "06" => "JUNE", "07" => "JULY", "08" => "AUGUST", "09" => "SEPTEMBER", "10" => "OCTOBER", "11" => "NOVEMBER", "12" => "DECEMBER");
query_posts(\'post_type=events&showposts=-1&meta_key=\' . $custom_metabox_event_dates->get_the_name(\'combined_datetime\') . \'&meta_compare=>=&meta_value=\' . $today . \'&orderby=meta_value&order=ASC\');
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php //Get all Events and run a check against current date
global $custom_metabox_event_dates;
global $custom_metabox_event_details;
$meta1 = $custom_metabox_event_dates->the_meta();
$meta2 = $custom_metabox_event_details->the_meta();
$meta_start_date = $meta1[\'event_start_date\'];
$meta_end_date = $meta1[\'event_end_date\'];
$meta_start_time = $meta1[\'event_start_time\'];
$meta_end_time = $meta1[\'event_end_time\'];
$meta_location_city = $meta2[\'event_location_city\'];
$meta_event_type = $meta2[\'event_type\'];
$show_date = strtotime($meta_start_date);
if($show_date >= $today) { ?>
<?php
$show_month = date(\'m\', $show_date);
if ($arrMonthNums[$show_month] == $show_month) {
echo "<div id=\'category-events-list-month-title\'>EVENTS IN ".$arrMonthNames[$show_month]."</div>";
$arrMonthNums[$show_month] = "printed";
}
if($show_date == $today) {
?>
<?php } ?>
<div id="category-events-list-container-group">
<div id="category-events-list-container-left">
<div id="event-entry-list-date"><?php echo $meta_start_date ?></div>
<div id="event-entry-list-time"><?php echo $meta_start_time ?> - <?php echo $meta_end_time ?></div>
</div>
<div id="category-events-list-container-right">
<div id="category-articles-list-title"><a href="<?php the_permalink() ?>"><?php echo the_title(); ?></a></div>
<div id="category-articles-list-excerpt">
<span>EVENT TYPE: <?php echo get_the_term_list($post->ID, \'event_types\', \'\', \', \',\'\'); ?> </span><br />
<span>LOCATION: <?php echo $meta_location_city ?></span><br />
<?php echo substr(get_the_excerpt(),0,250); echo \'... \' ?></div>
</div>
</div>
<?php } ?>
<?php endwhile; endif; ?>
请记住,我不是在问如何更改上面的查询,所以它只显示一个学期的帖子。。。相反,我需要以某种方式让归档页面识别单击了哪个术语,并将其与我在上面所做的排序/过滤一起通过查询传递。我假设这可能是一个简单的答案,其中涉及到我尚未掌握的“循环”。
UPDATED
这是存档页面的代码,需要修改,以便在从上面的结果列表中单击某个术语时,只显示相同的结果,但只显示按日期/时间选择和排序的术语,并消除任何早于今天日期的事件。<?php if (have_posts()) : ?>
<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
<?php /* If this is a category archive */ if (is_category()) { ?>
<div id="category-title-articles">Archive for the ‘<?php single_cat_title(); ?>’ Category</div>
<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
<div id="category-title-articles">Posts Tagged ‘<?php single_tag_title(); ?>’</div>
<?php } ?>
<?php while (have_posts()) : the_post(); ?>
<div id="category-articles-list-container-group">
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link(\'« Older Entries\') ?></div>
<div class="alignright"><?php previous_posts_link(\'Newer Entries »\') ?></div>
</div>
<?php else :
if ( is_category() ) { // If this is a category archive
printf("<h2 class=\'center\'>Sorry, but there aren\'t any posts in the %s category yet.</h2>", single_cat_title(\'\',false));
} else if ( is_date() ) { // If this is a date archive
echo("<h2>Sorry, but there aren\'t any posts with this date.</h2>");
} else if ( is_author() ) { // If this is a category archive
$userdata = get_userdatabylogin(get_query_var(\'author_name\'));
printf("<h2 class=\'center\'>Sorry, but there aren\'t any posts by %s yet.</h2>", $userdata->display_name);
} else {
echo("<h2 class=\'center\'>No posts found.</h2>");
}
get_search_form();
endif; ?>
提前感谢,克里斯