Using A Custom Page Template Based On PHP Switch Statement
-
Hi,
I am creating a Multsite Network for a particular group of users. The site includes a category hidden from the Site Admins in the WP dashboard. They cannot edit posts in this category or add new posts to this category. Only the Super Admin can do that.
Because I am using a custom post template for this category, the list of custom post templates is available to the Site Admin on the Edit/Add Post page. My best solution (so far) has been to have several templates created in another folder and use the PHP Switch statement to select the correct template for the post using a variable I have stored in the database.
Here is the code from my custom template:
<?php /* Template Name Posts: Niche Posts */ ?> <?php $niche = 'cow'; switch ($niche) { case "store": include "http://mysite.com/wp-content/uploads/stores/store-template.php" ; break; case "bar": echo "i is bar"; break; default: include "http://mysite.com/wp-content/themes/mytheme/template-fullwidth.php") ; break; } ?>
I am returned a blank page.
The templates work properly when called directly, but not when I try to include them.
I have also tried using the ABSPATH function, with similar results.
<?php include(ABSPATH . "../template-fullwidth.php") ; ?>
Any help someone can give would be appreciated.
- The topic ‘Using A Custom Page Template Based On PHP Switch Statement’ is closed to new replies.