WordPress.org

Ready to get started?Download WordPress

Forums

A-Z index list of post titles in taxonomy.php for a custom taxonomy term (1 post)

  1. design_dolphin
    Member
    Posted 4 years ago #

    This code will automatically build a A-Z index with post titles in alphabetical order based on a custom taxonomy term. YMMV.

    Version
    Wordpress 2.9.2
    (You might be able to use it for earlier versions, not sure)

    Validation

    The code is W3C validated, and also written for the visually impaired (as far as I know, please correct me if I am wrong at any point). You will have to edit the heading (h4, h5) tags to fit the theme you are using, in order to keep the heading tags aligned in your theme.

    Corrections/ improvements

    Beta code. Use at your own risk. Please feel to improve or correct where needed or wished for.

    In taxonomy.php:

    <?php  
    
    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    $list = '';       $query = $term->taxonomy .'=>'. $term->slug  ;
                  $posts = query_posts($query . '&nopaging=true' );
    	        	$groups = array();
     	if( $posts && is_array( $posts ) ) {
    		foreach( $posts as $post ) {
    		$first_letter = strtoupper( $post->post_name[0] );
    		$groups[ $first_letter ][] = $post;
       		ksort($groups);
    				}
    
    		if( !empty( $groups ) ) {{
               	$index_row_ta .='<ul class="topindex tic">';
    	         foreach ($groups as $letter => $posts) {
                	$index_row_ta .= '<li><h4 class="tatoct"><a rel="nofollow" href="#' . $letter . '-ta-ov-dossier" title="' . $letter . ' dossiers">' . apply_filters( 'the_title', $letter ) . '</a></h4></li>';
    		}
    		$index_row_ta .='</ul><br class="clear">';
    }    				 
    
    		$list .= '<ul class="index ic">';
    
    	 foreach( $groups as $letter => $posts ) {
    
                    $list .= '<li><a name="' . $letter . '-ta-ov-dossier"></a><h5 class="tatoc"><a class="il" rel="nofollow" href="#tags_top_ta_ov" title="Terug naar index">' . apply_filters( 'the_title', $letter ) . '</a></h5>';
       	        $list .= '<ul class="links">';
    
    			foreach( $posts as $post ) { 	
    
    			$url = esc_attr(get_option('home') . '/' . $term->taxonomy . '/' . $term->slug . '/' . $post->post_name . '.html');
    			$list .= '<li class="article"><a href="' . $url . '" title="' . the_title('', '', '0') .' ">' . the_title('', '', '0') . '</a></li>'; 
    
    	}
    	 		 $list .= '</ul></li>';
    	 		} 	
    
    			$list .= '</ul>'; 	
    
        	 	}
    		}
    
    		else $list .= '<p>Sorry, but no posts were found</p>';
    
      	 	?>
    
    <a name="tags_top_ta_ov"></a>
    
    <?php echo $index_row_ta; ?>
    <?php print $list; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 4 years ago by design_dolphin
  • This topic is not resolved
  • WordPress version: 2.9.1

Tags

No tags yet.