Skip to content
This repository has been archived by the owner. It is now read-only.

Update to cornerstone to hide private pages and adding list private pages template #92

Merged
merged 2 commits into from
Jan 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 97 additions & 83 deletions content-az.php
Original file line number Diff line number Diff line change
@@ -1,83 +1,97 @@
<?php
/**
* The template used for displaying page content in page.php
*
* @package cornerstone
*/

$exclude = get_post_meta(get_the_ID(), 'exclude', 'true');
$pattern = '#[A-Za-z|~`!@\#$%^&*()_+=|\\}\][{\'/;\-":?>.<]#';
?>


<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?>>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->

<div class="entry-content">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'cs' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->

<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, 'exclude' => $exclude));
if( !preg_match($pattern, $exclude, $matches) ){
$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>';
} else {
echo '<p>Invalid input in field: "exclude"</p>';
}
?>
</div>
<footer class="entry-footer">
<?php edit_post_link( __( 'Edit', 'cs' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-## -->
<?php
/**
* The template used for displaying page content in page.php
*
* @package cornerstone
*/

$exclude = get_post_meta(get_the_ID(), 'exclude', 'true');
$pattern = '#[A-Za-z|~`!@\#$%^&*()_+=|\\}\][{\'/;\-":?>.<]#';
?>


<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?>>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->

<div class="entry-content">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'cs' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->

<div id="az-index" class="clearfix">
<?php
function getChars(){
$pages = get_pages();
$letters = array();
foreach( (array) $pages as $pg ){
$parent = is_parent_private($pg->ID);
if($parent !== false) $page = $parent;
else $page = $pg->ID;
$private = get_post_meta($page, 'uc-private', true);
if($private == 'admins' || $private == 'users' || $private == 'list'){
continue;
}
$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, 'exclude' => $exclude));
if( !preg_match($pattern, $exclude, $matches) ){
$letters = array();
echo '<section class="letter-directory">';
foreach( (array) $pages as $pg ){
$parent = is_parent_private($pg->ID);
if($parent !== false) $page = $parent;
else $page = $pg->ID;
$private = get_post_meta($page, 'uc-private', true);
if($private == 'admins' || $private == 'users' || $private == 'list'){
continue;
}
$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>';
} else {
echo '<p>Invalid input in field: "exclude"</p>';
}
?>
</div>
<footer class="entry-footer">
<?php edit_post_link( __( 'Edit', 'cs' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-## -->
Loading