Try it with this in your theme’s functions.php: https://pastebin.com/bhb9pf5S
This allows you to have a query on a Page template for a single letter. Publish a Page where you want the letter results to be displayed and remember this Page slug. Query the loop like this on the Page template that is used for the published Page:
$letter_post_ids = get_letter_ids();
if($letter_post_ids) {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
//'posts_per_page' => 2,
'post__in' => $letter_post_ids,
'ignore_sticky_posts' => 1,
'post_type' => 'post',
'orderby' => 'title',
'order' => 'asc',
'paged' => $paged
);
query_posts($args);
}
// start of loop
while ( have_posts() ) : the_post();
?>
<!-- rest of loop -->
Put this in the template files where you want the letters (links) to show up (index.php, search,php):
<?php echo get_alphabet_links(); ?>
This will result in an unordered list of letter links that you can style with CSS.
The links will be going to urls like this but these pages will all use the same template (you published) for the results:
https://www.mysite/resultspageslug/a
https://www.mysite/resultspageslug/b
etc…
The only thing you have to change in the functions.php code for this to work is this:
define('RESULTS_PAGE_SLUG', 'articles');
define('LETTER_PREFIX', '');
Put your published results Page slug in the RESULTS_PAGE_SLUG define. I published a Page with the ‘articles’ slug on my site, so I used ‘articles in the difine’.
This gave me letter links with urls like this:
https://www.mysite/articles/a
https://www.mysite/articles/b
etc…
If you would like to prefix the letter you can change the LETTER_PREFIX define.
example:
define('RESULTS_PAGE_SLUG', 'articles');
define('LETTER_PREFIX', 'letter-');
This will result in letter links to urls like this:
https://www.mysite/articles/letter-a
https://www.mysite/articles/letter-b
etc …