Simplify conditional code using an array??
-
I have a block of code that works fine, but my feeling is that it should be something that PHP can accomplish in just a few lines of code, probably using an array somehow. I’ve been all over trying to find an answer, but if any of the PHP wizards here can help, that would be great.
I am checking the page title for certain strings created by NextGen Gallery and serving up an addendum to the post title based on which string is present. Here is my working code:
<?php // Create names for each portfolio page and display them after the portfolio title $mystring = wp_title('', false); $posweb = strpos($mystring, 'Gallery 9'); $posar = strpos($mystring, 'Gallery 10'); $posadv = strpos($mystring, 'Gallery 11'); $pospack = strpos($mystring, 'Gallery 12'); $poslogo = strpos($mystring,'Gallery 13'); $postrade = strpos($mystring, 'Gallery 14'); $posnews = strpos($mystring, 'Gallery 15'); $posbroch = strpos($mystring, 'Gallery 16'); if ($posweb == true) { echo ' » Web Sites'; } if ($posar == true) { echo ' » Annual Reports'; } if ($posadv == true) { echo ' » Advertising'; } if ($pospack == true) { echo ' » Packaging'; } if ($poslogo == true) { echo ' » Logos & Identity'; } if ($postrade == true) { echo ' » Trade Shows'; } if ($posnews == true) { echo ' » Newsletters'; } if ($posbroch == true) { echo ' » Brochures'; } // end create names for each portfolio page... ?>
I’d like to use this technique of checking for NextGen Gallery numbers in other areas of the site, but first I want to see how much simpler and shorter it can be.
Thanks for any and all advice.
cvc
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Simplify conditional code using an array??’ is closed to new replies.