Advertisement
Th3_G4m3r

template-redirect.php

Mar 2nd, 2013
775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. Template Name: Page Redirect
  5.  
  6. * @author Dave Stewart
  7. * @email dave@davestewart.co.uk
  8. * @web www.davestewart.co.uk
  9.  
  10. * @name Page Redirect
  11. * @type PHP page
  12. * @desc Wordpress template that redirects the current page based on the content of the database entry it loads
  13.  
  14. * @requires Wordpress
  15. * @install Copy this file to the directory of the theme you wish to use
  16. * usage
  17. 1. Create a new Page in your Wordpress control panel
  18. 2. Enter the URL (or local path, relative to your Wordpress directory) you want to redirect to as the only page content
  19. 3. Set the Page Template to "Page Redirect"
  20. 4. Publish
  21. */
  22.  
  23. if (function_exists('have_posts') && have_posts()){
  24. while (have_posts()){
  25.  
  26. // get the post
  27. the_post();
  28.  
  29. // get content
  30. ob_start();
  31. the_content();
  32. $contents = ob_get_contents();
  33. ob_end_clean();
  34.  
  35. // correctly build the link
  36.  
  37. // grab the 'naked' link
  38. $link = strip_tags($contents);
  39. $link = preg_replace('/\s/', '', $link);
  40.  
  41. // work out
  42. if(!preg_match('%^http://%', $link)){
  43. $host = $_SERVER['HTTP_HOST'];
  44. $dir = dirname($_SERVER['PHP_SELF']);
  45. $link = "http://$host$dir/$link";
  46. }
  47.  
  48. // do the link
  49. header("Location: $link");
  50. die('');
  51. }
  52.  
  53. }
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement