Advertisement
sparkweb

Custom Template Styles Based on Querystring

Sep 22nd, 2011
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  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. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement