Display different content based on user’s past page

<?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>';
}
}
view raw gistfile1.aw hosted with ❤ by GitHub

cookies tracking

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.

Let's Talk