2012-12-02 35 views
0

我需要在wordpress中顯示按字母順序排列的名稱列表。在wordpress中創建按字母順序排列的分頁

例....當選擇乙..

çd ... X YŽ

巴希爾| Bastien | Belta |比利| Bynoo

,當我點擊一個,我只需要名字以A開頭...

我發現這個代碼on PasteBin ...但它創造的完整列表,

我需要的所有字母出現像ABCD ..... XYZ ...........並只顯示起始字母的選擇名稱...

回答

3

也許不是最好的方法,雖然這就是我剛剛做到的。

<?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> 
+0

我會建議您查看字母分頁的腳本,它可以隨處使用。 http://wordpress.org/plugins/alphabetic-pagination/ –