I’m wondering if there is a more efficient way to write the following, as the first group of URLs all have the same result. Thanks in advance.
<?php
if (stripos($_SERVER['REQUEST_URI'],'/feet-foxes/') !== false) {
echo '';
}
elseif (stripos($_SERVER['REQUEST_URI'],'/aerial-immersion/') !== false) {
echo '';
}
elseif (stripos($_SERVER['REQUEST_URI'],'/taste-paper-air/') !== false) {
echo '';
}
elseif (stripos($_SERVER['REQUEST_URI'],'/dance-movement-therapy-group/') !== false) {
echo '';
}
elseif (stripos($_SERVER['REQUEST_URI'],'/fencing-fun/') !== false) {
echo '';
}
elseif ($ticketlink = get_post_meta($post->ID, 'Ticket-Link-1', true)) {
echo '<div class="artist-buy-tickets-box"><a class="artist-buy-button" href="'.$ticketlink.'" title="Buy tickets" target="_blank">Buy Tickets</a>';
}
else {
echo '<h6>TICKETS ON SALE<br/>JUNE 15 2011</h6>';
}
?>
I ‘m quite sure what your criteria for efficiency are, but here’s a nicer alternative. It requires PHP >= 5.3 for the anonymous function (it can be done in earlier versions, but using
create_functionis kind of a chore).My apologies for the atrocious indenting — I couldn’t come up with anything substantially less ugly.