All pastes #1730939 Raw Edit

Wordpress - Tag Index Page Templ

public php v1 · immutable
#1730939 ·published 2009-12-29 18:24 UTC
rendered paste body
<?php/*Template Name: Tag Index*/get_header(); ?><div id="content" class="widecolumn">		<h2><?php the_title() ?></h2>		<!-- 	Feel free to add regular stuff you want here, like the_content() etc...	-->		<?php 		$valid_characters = range( 'a' , 'z' );	$valid_numbers = array(1,2,3,4,5,6,7,8,9,0);	$nav = array();	// Build nav array	foreach( $valid_characters as $key => $character ) 		$nav[] = '<a href="' . get_permalink( $post->ID ) . '?tags=' . $character . '">' . strtoupper( $character ) . '</a>';	foreach( $valid_numbers as $key => $number ) 		$nav[] = '<a href="' . get_permalink( $post->ID ) . '?tags=' . $number . '">' . $number . '</a>';	// Array to hold tags, needs to be set, so the empty check works when none of the switch cases hit a match (for whatever reason)	$tags = array();	// Array that will hold arrays of tags based on their first letter	$tag_array = array();		// Main switch	switch( true ) {		// If request for tag with particular letter		case ( isset( $_GET['tags'] ) ):			// If it's in the arrays created earlier, get tafs and sort into array			case ( in_array( $_GET['tags'] , $valid_characters ) || in_array( $_GET['tags'] , $valid_numbers ) ):				$tags = get_terms( 'post_tag' , "hide_empty=0&name__like=$_GET[tags]" );								if( !empty( $tags ) ) {					foreach( $tags as $tag ) {						$tag_array[$tag->name{0}][] = '<li><a href="'.get_tag_link( $tag->term_id ).'">'.$tag->name.'</a></li>';					}				}			break;		break;		case ( !isset( $_GET['tags'] ) ):			default:			$tags = get_terms( 'post_tag' , 'hide_empty=0' );						if( !empty( $tags ) ) {				foreach( $tags as $tag ) {					$tag_array[$tag->name{0}][] = '<li><a href="'.get_tag_link( $tag->term_id ).'">'.$tag->name.'</a></li>';				}			}		break;	}	// If theres only one item in the array ( well one key ) , then it's a requested tag letter, so add a "Show all" link at the start of the nav	if( count( $tag_array ) == 1 ) array_unshift( $nav , '<a href="' . get_permalink( $post->ID ) . '">Show all</a>' );		// Print out the nav array, implode is just an easy way to put seperators in that's all!.. ;)	// In the implode function, the | is the separtor, feel free to change it (make sure to leave the single quotes)	?>	<div class="nav">		<?php echo implode( ' | ' , $nav );?>	</div>		<?php	// If there's tags in the array	if( !empty( $tag_array ) ) {		foreach( $tag_array as $character => $character_tags ) {		?>			<div class="tagindex">				<h4><?php echo $character; ?></h4>				<ul class="links">					<?php foreach( $character_tags as $key => $tag ) { echo $tag; } ?>				</ul>			</div>					<?php		}	} 	else {		?>		<h4>No tags found</h4>		<?php	}	?></div><?php get_footer(); ?>