How do I consolidate this code: using conditional tags
-
I am using conditional tags to display different headers on each page.
There are three different headers total, so I should only need three different conditional tags/statements(forgive me for the botched jargon). Instead I have a conditional tag for each page, which seems too much. Is there a way to use the same tag for several pages?
Example:
[please use backticks or the ‘code’ button to mark your code]
<?php if(is_page('Home') ){ echo '<img src="https://www.exceptionalit.com/wp-content/themes/Exceptional%20IT%201%20Column/images/home.png"/>'; } ?> <?php if(is_page('Resources') ){ echo '<img src="https://www.exceptionalit.com/wp-content/themes/Exceptional%20IT%201%20Column/images/home.png"/>'; } ?> <?php if(is_page('News') ){ echo '<img src="https://www.exceptionalit.com/wp-content/themes/Exceptional%20IT%201%20Column/images/home.png"/>'; } ?> <?php if(is_page('Articles and Case Studies') ){ echo '<img src="https://www.exceptionalit.com/wp-content/themes/Exceptional%20IT%201%20Column/images/home.png"/>'; } ?>
See what I mean? They all do the same thing for each page. Certainly I can just put a list of the pages in one of the statements. I tried using “array” and couldn’t get it right.
Thanks!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How do I consolidate this code: using conditional tags’ is closed to new replies.