我需要在wordpress中显示按字母顺序分页的名称列表。
示例....选择B时..
B C D ... X Y Z
Bassil |巴斯蒂安| Belta |比利| Bynoo
当我点击A时,我只需要以A ...开头的名字
我发现此代码on PasteBin ...但它会创建完整列表
我需要所有字母看起来像A B C D ..... X Y Z ...........并且只显示选择了起始字母的姓名......
答案 0 :(得分:4)
也许不是最好的方法,虽然这就是我刚刚做到的。
<?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>