This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting up AZ index
- Loading branch information
andrewmbacon
committed
Jul 21, 2014
1 parent
0014d58
commit 454ab50
Showing
4 changed files
with
502 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/* | ||
Template Name: A-Z Index | ||
*/ | ||
get_header(); ?> | ||
|
||
<div class="row" id="primary"> | ||
<div class="col-sm-12"> | ||
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> | ||
<div class="post content clearfix" id="post-<?php the_ID(); ?>"> | ||
<h1> | ||
<?php the_title(); ?> | ||
</h1> | ||
<div class="post-content"> | ||
<?php the_content(); ?> | ||
</div> | ||
<div id="az-index" class="clearfix"> | ||
<?php | ||
|
||
function getChars(){ | ||
$pages = get_pages(); | ||
$letters = array(); | ||
foreach( (array) $pages as $pg ){ | ||
$title = ucwords($pg->post_title); | ||
$char = $title{0}; | ||
if( !(is_numeric($char)) && !in_array($char, $letters) ){ | ||
array_push($letters, $char); | ||
} | ||
} | ||
return $letters; | ||
} | ||
|
||
// Generate AZ Navigation | ||
echo '<nav class="btn-group">'; | ||
$anchors = getChars(); | ||
foreach( range('A', 'Z') as $char ){ | ||
if( in_array( $char, $anchors ) ){ | ||
echo '<a href="#'.$char.'-pages" class="btn btn-default">'.$char.'</a>'; | ||
} else { | ||
echo '<span class="btn btn-default disabled">'.$char.'</span>'; | ||
} | ||
} | ||
echo '</nav>'; | ||
|
||
// Generate AZ List | ||
$pages = get_pages(array('sort_order' => 'asc', 'sort_column' => 'post_title', 'hierarchical' => false)); | ||
$letters = array(); | ||
echo '<section class="letter-directory">'; | ||
foreach( (array) $pages as $pg ){ | ||
$title = ucwords($pg->post_title); | ||
$char = $title{0}; | ||
if( !( is_numeric($char) || empty($char) ) ){ | ||
if( $char != end($letters) && !empty($letters) ){ | ||
echo '</ol></div>'; | ||
} | ||
if( !in_array($char, $letters) ){ | ||
echo '<div class="az-letter"><a name="'.$char.'-pages" class="az-anchor"></a><h2 id="'.$char.'-pages az-letter-title"><span class="az-letter">'.$char.'</span></h2><ol class="az-letter-list">'; | ||
array_push($letters, $char); | ||
} | ||
echo '<li><a href="'.get_page_link($pg->ID).'" class="az-letter-page">'.$title.'</a></li>'; | ||
} | ||
} | ||
echo '</ol></div></section>'; | ||
?> | ||
</div><!-- /az --> | ||
</div><!-- /post --> | ||
<?php endwhile; endif; ?> | ||
</div><!-- /span-12 --> | ||
</div><!-- /row --> | ||
<?php get_footer(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.