Created
March 19, 2017 06:34
-
-
Save matt-vaden/bed2aad4c423aa69e8caad6e6a9623ad to your computer and use it in GitHub Desktop.
Example PHP Loop Using Switch and Case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load Testimonials script for specific pages | |
add_action( 'pre_get_posts', 'mv_show_testimonials_script' ); | |
function mv_show_testimonials_script() { | |
if ( is_page('services') || is_home() || is_front_page() ) { | |
// Let's set some server vars | |
if(strpos($_SERVER['REQUEST_URI'], 'staging1') !== false) { | |
$mv_server = 'stage_one'; | |
} elseif (strpos($_SERVER['REQUEST_URI'], 'staging2') !== false) { | |
$mv_server = 'stage_two'; | |
} elseif (strpos($_SERVER['REQUEST_URI'], '192.168.1.10') !== false) { | |
$mv_server = 'local'; | |
} elseif (strpos($_SERVER['REQUEST_URI'], 'mattvaden.com') !== false) { | |
$mv_server = 'live_tlms'; | |
} | |
// Now we include the tlms script from the correct dir | |
switch ($mv_server) { | |
case "stage_one": | |
$mv_stage_one_tlms = include_once ('/some/home/dir/staging/1/wp-content/plugins/tmls_testimonials/testimonials.php'); | |
var_dump($mv_stage_one_tlms); | |
break; | |
case "stage_two": | |
$mv_stage_two_tlms = include_once ('/some/home/dir/staging/2/wp-content/plugins/tmls_testimonials/testimonials.php'); | |
var_dump($mv_stage_two_tlms); | |
break; | |
case "local": | |
$mv_local_tlms = include_once ('C:\xampp\htdocs\some\home\dir\wp-content\plugins\tmls_testimonials\testimonials.php'); | |
var_dump(mv_local_tlms); | |
break; | |
case "live_tlms": | |
$mv_live_tlms = include_once ('/some/home/dir/public_html/wp-content/plugins/tmls_testimonials/testimonials.php'); | |
var_dump($mv_live_tlms); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment