daily pastebin goal
49%
SHARE
TWEET

Custom Template Styles Based on Querystring

sparkweb Sep 22nd, 2011 180 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //This filter will look an alternate template that matches displaystyle in the querystring
  3. //http://mysite.com/products/my-product/?displaystyle=style1 will search for foxyshop-single-product-style1.php
  4. //If it doesn't find it, the original file will be returned
  5. //This feature is helpful for creating different styles which can be referenced by changing the querystring
  6. //This snippet can go in functions.php
  7. add_filter('foxyshop_template_redirect', 'my_foxyshop_template_redirect', 5, 2);
  8. function my_foxyshop_template_redirect($final_url, $original_filename) {
  9.         if (isset($_GET['displaystyle'])) {
  10.                 $newfilename = str_replace(".php", '-' . sanitize_title_with_dashes($_GET['displaystyle']) . '.php', $original_filename);
  11.                 if (file_exists(STYLESHEETPATH . '/' . $newfilename)) {
  12.                         return STYLESHEETPATH . '/' . $newfilename;
  13.                 }
  14.         }
  15.         return $final_url;
  16. }
  17. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top