wordpress - Conditional formatting of single.php based on previous page? -
here's 1 that's been eating @ me.
i've got collection of 12 posts called "products" have been assigned categories, let's "military", "trucking", "construction", , "railroad". lot of them overlap, product 1 may applicable both military , trucking , product 2 railroad, example. easy enough.
here's gets fun. military page (which using 1 template) bringing in of products have been assigned military category , same trucking (which using different template). , good, when click through product 1, want retain template of page had been on.
so basically, how have formatting single.php generated based on page entered from? possible?
what on page load have page check cookie of previous page id. check layout page id , serve that.
put in footer.php
file:
global $wp_query; // global query object $post_id = $wp_query->post->id; // set id variable setcookie('last_id', $post_id, false, '/'); // set cookie subsequent requests
this set cookie after of code ran on current page. setting cookie next page. can check in code single template:
if(isset($_cookie['last_id']){ $id = intval($_cookie['last_id']); // code setting template }
Comments
Post a Comment