Issue with getting switch/case statement to work properly
-
I have created a custom page template to dynamically change what content is displayed in the “Gallery” based on a Custom Field set for each page.
In this template I have written a Switch statement to change the value for “$gallery”, which is being used in $args for the WP_Query function I am using to pull in the thumbnails, titles, links etc. for the Gallery.
The functions work to display the content, but my Switch only works for the case I list first. If I change the case listed first it works properly for each case, just not for any other case.
I am a PHP noob so I am sure I am missing something simple with the break/continue, I just can’t figure out what it is.
Example of “Gallery Page” that works: http://beta.3blindmiceusa.com/featured/
Code for Switch:
<span id="gallerymeta"><?php $gallery_category = print_r ($gallery_cats); switch ($gallery_category) { case "137": $gallery="shades"; break; case "185": $gallery="window-film-window-tinting"; break; case "174": $gallery="featured-window-coverings"; break; case "148": $gallery="shutters"; break; } ?> </span> <?php $args = array( 'post_type' => 'page', 'gallery' => $gallery, 'posts_per_page' => '-1', ); $the_query = new WP_Query( $args ); ?>
The topic ‘Issue with getting switch/case statement to work properly’ is closed to new replies.