All pastes #1747489 Raw Edit

Page template - Tag Indexer

public php v1 · immutable
#1747489 ·published 2010-01-11 22:14 UTC
rendered paste body
<?php/*Template Name: Tag Indexer*/get_header();// Create some empty arrays$t = $tags_nav = $nav = $to_show = array();// Create some empty strings$navi = $tags = '';// What to seperate the character links with$nav_sep = ' | ';// What to seperate the tags with$tag_sep = '<br />';// Page data$id = (int) get_the_ID();$title = get_the_title( $id );$post_url = get_permalink( $id );$nav_url = ( strpos( $post_url , '?' ) != false ) ? $post_url . '&tags=' : $post_url . '?tags=';$excludes = array( 	16,58,59,60,61,62,63,64,65,66,67,68,69,70,72,71,73,74,75,76,77,78,79,80,	81,82,83,84,85,86,87,88,90,101,102,103,104,105,106,107,108,109,110,112,113,	114,115,116,117,118,119,120,121,122,123,125,126,127,128,129,130,131,132,	133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,	151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,	169,170,171,172,173,174,175,176,177,178,179,180,213,354,355,380,381 );$valid_chars = array(	'a','b','c','d','e',	'f','g','h','i','j',	'k','l','m','n','o',	'p','q','r','s','t',	'u','v','w','x','y',	'z','0','1','2','3',	'4','5','6','7','8',	'9');$terms = get_terms( 'post_tag' , 'hide_empty=0' );// Loop over all the tagsforeach( $terms as $term ) {	// If the tag ID (term_id) is in the exclude array, continue ( which means move to the next item in the loop )	if( in_array( $term->term_id , $excludes ) ) continue;	/* Sorter loop, groups the tags by first letter/number 		Examples:		$t['a'] = tag Array		$t['a'][0] = tag Array first key Object 		$t['b'][0] = tag Array first key Object 		$t['b'][1] = tag Array second key Object 	*/		$t[strtolower($term->name{0})][] = $term;}// Unset some variables no longer neededunset( $terms , $term );if( !empty( $t ) )	// Get the sorter array keys, so we know which letters and numbers should show in the nav	$tags_nav = array_keys( $t );if( !empty( $tags_nav ) ) {	// If the nav has items (if there are tags)	foreach( $tags_nav as $character ) {		$nav[] = '<a href="' . $nav_url . $character . '">' . strtoupper( $character ). '</a>';	}}// If nav isn't empty / if there's tagsif( !empty( $nav ) ) {	switch( true ) {		case( !isset( $_GET['tags'] ) ):			$navi = implode( $nav_sep , $nav );		break;		case( isset( $_GET['tags'] ) && in_array( strtolower( $_GET['tags'] ) , $valid_chars ) ):			$navi = implode( $nav_sep , $nav );			$tags = $t[strtolower( $_GET['tags'] )];		break;	}}// If array (empty string if no tags)if( is_array( $tags ) ) {	foreach( $tags as $tag ) {		$to_show[] = '<a href="'.get_tag_link( $tag->term_id ).'">'.$tag->name.'</a>';	}}// get_sidebar();// Output below// Title is taken from the page you attached the template to?>	<div class="content">		<h2><?php echo apply_filters( 'the_title' , $title ); ?></h2>		<?php echo $navi ;?><br />		<?php echo ( !empty( $to_show ) ) ? implode( $tag_sep , $to_show ) : ''; ?>	</div><?phpget_footer(); ?>