WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want add a pagination

How can I do this on both loop.php and search.php. I want show alphabetic index to search only posts with starting letter = [E] for example. Right now, if I search with E it search for any match, title+content+part of title.

[A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] .......[Z]

Easy Post Title - By Admin on 2013

post content....bla bla bla...

Example Post - Another Test - By Admin on 2013

post content....bla bla bla...

[A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] .......[Z]

share|improve this question
possible duplicate of Wordpress A-Z Navigation. Check this search results too: wordpress.stackexchange.com/search?q=%22a-z%22 – brasofilo Jul 7 '13 at 17:43

This is the code I get from here, but I don't remember the exact page, and this is my working page of letter B on my website (using the same code as you see below)

Template Name: Locali per lettera

A WordPress template to list page titles by first letter.

You should modify the CSS to suit your theme and place it in its proper file.
Be sure to set the $posts_per_row and $posts_per_page variables.

$posts_per_row = 3;
$posts_per_page = -1;
$pageURL = 'http';
$post_type = 'post';

if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
} else {

$letters = $wpdb->get_col(
"SELECT DISTINCT LEFT(post_title,1) AS first_letter FROM $wpdb->posts
WHERE post_type = '$post_type' AND post_status = 'publish'
ORDER BY first_letter ASC"

$first_letter = ($_GET['first_letter']) ? $_GET['first_letter'] : $letters[0];

<?php get_header(); ?>

 <style type="text/css">
 .letter-group { width: 100%; border-top: 1px solid #444; }
  .navigation { text-align: center; padding:5px; margin: 0 10px;} 
 .letter { display:inline; color:#DDD;text-align: center; padding: 2px; border-top: 1px solid #48465B; border-left: 1px solid #48465B; background: #18181C; margin: 0 1px;} 
 .letter a{ color:#DDD;} 
 .letter-cell { width: 5%; color:red; font-weight:bold; height: 2em; text-align: center; padding-top: 8px; margin-bottom: 8px; border-top: 1px solid #48465B; background: #18181C; float: left; }
 .row-cells { width: 94%; float: right;  }
 .title-cell { width: 33%;  float: left; overflow: hidden; margin-bottom: 8px; }
.alignleft {
    float: left;
    margin-left: 25px;
.alignright {
    float: right;
    margin-right: 25px;
 .clear { clear: both; }
 div#a-z .padder {
    border-right: none;
    margin-right: none;
    padding: 20px 40px;

<div id="main-background">

   <div id="main-column">
    <br />
      <h2><?php the_title(); ?></h2>

      <div class="margin-top"></div>

      <div id="a-z">

         $mam_global_where = " AND LEFT(post_title,1) = '$first_letter' ";
         $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
         $args = array (
            'posts_per_page' => $posts_per_page,
            'post_type' => $post_type,
            'orderby' => 'title',
            'order' => 'ASC',
            'paged' => $paged,
            'caller_get_posts' => 1
         $mam_global_where = '';  // Turn off filter
         if ( have_posts() ) {
            $in_this_row = 0;
            while ( have_posts() ) {
               $first_letter = strtoupper(substr(apply_filters('the_title',$post->post_title),0,1));
               if ($first_letter != $curr_letter) {
                  if (++$post_count > 1) {
                  $curr_letter = $first_letter;
               if (++$in_this_row > $posts_per_row) {
                  ++$in_this_row;  // Account for this first post
               } ?>
               <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 }
            <div class="navigation">
            foreach ($letters as $letter) {
               $url = add_query_arg('first_letter',$letter,$pageURL);
               echo "<div class='letter'>";
               echo "<a href='$url' title='Starting letter $letter' > $letter </a>";
               echo "</div>";

         <?php } else {
            echo "<h2>Sorry, no posts were found!</h2>";

      </div><!-- End id='a-z' -->
   </div><!-- End class='margin-top --> 
</div><!-- End id='rightcolumn' -->

function end_prev_letter() {
   echo "</div><!-- End of letter-group -->\n";
   echo "<div class='clear'></div>\n";
function start_new_letter($letter) {
   echo "<div class='letter-group'>\n";
   echo "\t<div class='letter-cell'>$letter</div>\n";
function end_prev_row() {
   echo "\t</div><!-- End row-cells -->\n";
function start_new_row() {
   global $in_this_row;
   $in_this_row = 0;
   echo "\t<div class='row-cells'>\n";

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.