也許不是最好的方法,雖然這就是我剛剛做到的。
<?php
/**
* Template Name: Shop
**/
$posts_per_row = -1;
$posts_per_page = -1;
$curr_letter = $_GET["character"];
?>
<div>
<div class="alphanav">
<a href="<?php bloginfo('url'); ?>/shops/?character=A">A</a>
<a href="<?php bloginfo('url'); ?>/shops/?character=B">B</a>
<a href="<?php bloginfo('url'); ?>/shops/?character=C">C</a>
</div>
<div>
<h1><?php the_title(); ?></h1>
<div id="a-z">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array (
'posts_per_page' => $posts_per_page,
'post_type' => 'shop',
'orderby' => 'title',
'order' => 'ASC',
'paged' => $paged
);
query_posts($args);
if (have_posts()) {
while (have_posts()) {
the_post();
$first_letter = strtoupper(substr(apply_filters('the_title',$post->post_title),0,1));
if ($first_letter == $curr_letter) { ?>
<div class="title-cell"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
<?php } ?>
<?php } ?>
<?php } else {
echo "<h2>Sorry, no posts were found!</h2>";
}
?>
</div><!-- End id='a-z' -->
</div>
</div>
我會建議您查看字母分頁的腳本,它可以隨處使用。 http://wordpress.org/plugins/alphabetic-pagination/ –