Create alphabetical Pagination in wordpress [closed]

十年热恋 提交于 2021-02-11 12:35:09

问题


I need to display list of names with alphabetical pagination in wordpress.

Example.... when B is selected..

A B C D...X Y Z

Bassil | Bastien | Belta | Billy | Bynoo

and when i click A, i need only names starting with A...

I found this code on PasteBin ... but it create the full list,

I need all letters to appear like A B C D ..... X Y Z ........... and only display names with starting letter selected...


回答1:


Maybe not the best method, although this is how I just did it.

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


来源:https://stackoverflow.com/questions/13671943/create-alphabetical-pagination-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!