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
<?php | |
/** | |
* functions.php | |
* | |
*/ | |
// Use single template file for Design Gallery archive and Taxonomy | |
add_filter('template_include', 'be_design_gallery_template', 1, 1); | |
function be_design_gallery_template($template) { | |
if( is_tax( 'template-type' ) ) $template = dirname(__FILE__) . '/archive-template.php'; | |
return $template; | |
} | |
/** | |
* archive-template.php | |
* | |
*/ | |
// Save the page | |
session_start(); | |
if (is_tax()) $_SESSION['original'] = get_query_var('template-type'); | |
else $_SESSION['original'] = 'all'; | |
/** | |
* single-template.php | |
* | |
*/ | |
// Start Session to receive previous page info | |
session_start(); | |
if(!isset($_SESSION['original'])) $_SESSION['original'] = 'all'; | |
// Put this where you want the navigation to appear | |
be_post_navigation(); | |
/** | |
* Post Navigation (included from /lib/functions/design-template-functions.php ) | |
* Uses the plugin 'previous-and-next-post-in-same-taxonomy'. See plugin for more information | |
* @link http://wordpress.org/extend/plugins/previous-and-next-post-in-same-taxonomy/ | |
* | |
*/ | |
function be_post_navigation() { | |
// Get Previous/Next Post Data | |
// -- If patch is active | |
if (function_exists('be_get_previous_post')) { | |
if ($_SESSION['original'] == 'all') { | |
$previous = be_get_previous_post(false, '', ''); | |
$next = be_get_next_post(false, '', ''); | |
} else { | |
$previous = be_get_previous_post(true, '', 'template-type'); | |
$next = be_get_next_post(true, '', 'template-type'); | |
} | |
// -- If patch is inactive | |
}else{ | |
if ($_SESSION['original'] == 'all') { | |
$previous = get_previous_post(false, '', ''); | |
$next = get_next_post(false, '', ''); | |
} else { | |
$previous = get_previous_post(true, '', 'template-type'); | |
$next = get_next_post(true, '', 'template-type'); | |
} | |
} | |
// Display Previous | |
if (!empty($previous)) { | |
echo '<a href="'.get_permalink($previous->ID).'" class="link-prev">'; | |
$image_ids = array_keys( get_children( array( 'post_parent' => $previous->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC' ) ) ); | |
$image = wp_get_attachment_image_src( $image_ids[0], 'template-nav'); | |
echo '<img src="'.$image[0].'" alt="" />'; | |
echo '<span>'.get_the_title($previous->ID).'</span></a>'; | |
} | |
// Display Next | |
if (!empty($next)) { | |
echo '<a href="'.get_permalink($next->ID).'" class="link-next">'; | |
$image_ids = array_keys( get_children( array( 'post_parent' => $next->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC' ) ) ); | |
$image = wp_get_attachment_image_src( $image_ids[0], 'template-nav'); | |
echo '<img src="'.$image[0].'" alt="" />'; | |
echo '<span>'.get_the_title($next->ID).'</span></a>'; | |
} | |
} |