0

ワードプレスでアルファベット順のページネーションで名前のリストを表示する必要があります。

例…Bを選択した場合…

A B C D...XYZ

バジル | バジル | バスティアン | ベルタ | ビリー | ビリー | バイヌー

Aをクリックすると、Aで始まる名前だけが必要です...

PasteBinでこのコードを見つけました...しかし、完全なリストを作成し、

すべての文字が ABCD ..... XYZ ........... のように表示される必要があり、開始文字が選択された名前のみが表示されます...

4

1 に答える 1

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>
于 2012-12-09T04:14:04.073 に答える