【问题标题】:Create alphabetical Pagination in wordpress [closed]在wordpress中创建字母分页[关闭]
【发布时间】:2012-11-20 06:01:57
【问题描述】:

我需要在 wordpress 中显示按字母分页的名称列表。

示例....选择b时..

A B C D...X Y Z

罗勒|巴斯蒂安 |贝尔塔 |比利 |拜诺

当我点击 A 时,我只需要以 A 开头的名称...

我找到了这段代码on PasteBin ...但它创建了完整的列表,

我需要所有字母都显示为 A B C D ..... X Y Z ...... 并且只显示选择了起始字母的名称...

【问题讨论】:

    标签: php wordpress pagination alphabetical letters


    【解决方案1】:

    也许不是最好的方法,尽管我就是这样做的。

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多