<?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>'; | |
} | |
} |
Bill Erickson
Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.
Ready to upgrade your website?
I build custom WordPress websites that look great and are easy to manage.
Other articles in this series
10 ways to speed up your WordPress website
July 17, 2018
A slow website is painful to use, less engaging to visitors, and hurts your search engine rankings. I’ll walk you through the tools I use to identify performance problems, and provide ten tips to improve your website’s performance
Custom recipe templates for WP Recipe Maker
October 7, 2019
I frequently work with food bloggers to improve the design, speed, and functionality of their websites. The recipe card is the most important element on the page. It should be…
Git based code deployment on Big Scoots
February 21, 2020
A guide to setting up git for code deployment on Big Scoots, a popular managed WordPress host.
InnerBlocks with ACF blocks
September 8, 2020
Use InnerBlocks to insert any block (core or custom) inside your custom ACF block. Set the default content, limit which blocks can be used, and more.