谁能指出我正确的方向?我试图让分页工作,因为我在页面上的条目太多(请参阅下面的示例页面链接),但完全处于杂草之中。
这是一个存档页面,它根据自定义字段(开始日期)列出自定义帖子,并在开始日期过去时将它们从列表中删除。
这是一个示例页面: http: //www.musicfestivaljunkies.com/festival-guide/us-festivals/
这是我一直在使用的代码:
<?php
/**
* Do we need to filter by event tag?
*/
if(is_tax('event_tags') ) :
$tag = strip_tags( get_query_var('event_tags') );
$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta, $wpdb->terms wterms, $wpdb->term_taxonomy wtax, $wpdb->term_relationships wrels
WHERE wposts.ID = wpostmeta.post_id
AND wterms.term_id = wtax.term_id
AND wtax.term_taxonomy_id = wrels.term_taxonomy_id
AND wrels.object_id = wposts.ID
AND wterms.slug = '$tag'
";
else:
$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id";
endif;
// Build the rest of the query, i.e. only get events with dates, and order newest first.
$querystr .= "
AND wpostmeta.meta_key = 'Date'
AND STR_TO_DATE(wpostmeta.meta_value,'%m/%d/%Y') >= CURDATE()
AND wposts.post_status = 'publish'
AND wposts.post_type = 'events'
ORDER BY STR_TO_DATE(wpostmeta.meta_value,'%m/%d/%Y') ASC
";
$events = $wpdb->get_results($querystr, OBJECT);
if ($events):
echo '<ul>';
foreach ($events as $post):
global $post;
setup_postdata($post);
// Get a friendlier version of the date.
$date = get_post_meta($post->ID, 'Date', true);
$date = date_create($date);
$date = date_format($date, 'jS F, Y');
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> - <?php echo $date; ?></li>
<?php endforeach;
echo '</ul>';
endif; ?>