I want to create an A to Z index listing of all posts from a specific custom post type.
This is the code so far:
<?php
/**
* The Template for displaying archive series.
*
* Theme: Default
*/
get_header(); ?>
<div id="content">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('paged' => $paged,'posts_per_page' => -1,'post_type' => 'series_type','post_status' => 'publish','orderby' => 'title','order' => 'asc');
$fruits = new WP_Query($args);
if($fruits->have_posts()){
$current_first_letter="";
$t = array();
$s = array();
while($fruits->have_posts()){
$fruits->the_post();
$title = get_the_title();
if(is_string($title)){
$first_letter = strtoupper($title[0]);
if($first_letter != $current_first_letter){
$t[] = $first_letter;
$current_first_letter = $first_letter;
}
}
$s[$first_letter][] = get_the_title();
}
}
$t = array_unique($t);
$tc = count($t);
$sc = count($s);
for($i=0; $i<$tc; $i++){
?>
<div>
<h4><?php echo $t[$i]; ?></h4>
<ul>
<?php
foreach($s as $key => $value){
if($key == $t[$i]){
$vc = count($value);
for($j=0; $j<$vc; $j++){
?>
<li><?php echo $value[$j]; ?></li>
<?php
}
}
}
?>
</ul>
</div>
<?php
}
if($fruits->max_num_pages > 1){ ?>
<nav class="prev-next-posts">
<div class="prev-posts-link">
<?php echo get_next_posts_link( 'Older Entries', $fruits->max_num_pages ); ?>
</div>
<div class="next-posts-link">
<?php echo get_previous_posts_link( 'Newer Entries' ); ?>
</div>
</nav>
<?php } ?>
<?php wp_reset_postdata(); ?>
</div><!-- #content -->
<?php get_footer(); ?>
The problem is I don’t know how to make all of them as hyperlinks instead of raw text. Can anyone help me fix the code?