});
add_filter('get_county_by_city', function( $city ) {
global $wpdb;
+ if (is_string($city)) {
+ // Could make this a subquery below but this way it only gets run on member detail pages
+ // where the city is not retrieved from $_REQUEST as an integer, but from $member.name as a string
+ $citySql = "SELECT C.id FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."cities C "
+ . "WHERE C.name = '$city' "
+ . "LIMIT 1"
+ . ";";
+ $city = $wpdb->get_var($citySql);
+ }
+
$sql = "SELECT C.id FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."counties C "
. "WHERE C.id IN ("
. "SELECT M.county "
}
}
}
+}
+/*
+ * If a destination is searched for, display the ad for the city corresponding to that destination
+ * (e.g. Petoskey Area destination => Petoskey city => Petoskey Area CVB ad)
+ * If a city is searched for, if it is one of certain cities, display the ad for that city.
+ * If it is not one of those cities check the county associated with the city searched for
+ * Otherwise, If a city is not searched for, check for the county that is searched for,
+ * then display the ad for that county
+ *
+ */
+function display_top_ads($city, $county, $destination) {
+ // To avoid duplicate code and ease maintenance, for destinations use the same ads that the cities use, below
+ switch ($destination) {
+ case 22: // Petoskey Area
+ $city = 89; // Petoskey
+ break;
+ case 23: // Gaylord Area
+ $city = 37; // Gaylord
+ break;
+ case 24: // Traverse City Area
+ $city = 106; // Traverse City
+ break;
+ default:
+ break;
+ }
+ switch ($city) { // Find by city first, specific list given by client
+ case 37: // Gaylord County
+ echo do_shortcode("[the_ad id='1182']"); // Show Gaylord Area CVB ad
+ break;
+ case 89: // Petoskey County
+ echo do_shortcode("[the_ad id='1180']"); // Show Petoskey Area CVB ad
+ break;
+ case 106: // Traverse City County
+ echo do_shortcode("[the_ad id='1186']"); // Show Traverse City CVB ad
+ break;
+ default: // If a specific city override is not found, look at the county
+ switch ($county) {
+ case 40: // Crawford County
+ case 2: // Montmorency County
+ case 8: // Otsego County
+ echo do_shortcode("[the_ad id='1182']"); // Show Gaylord Area CVB ad
+ break;
+ case 9: // Charlevoix County
+ case 13: // Emmet County
+ echo do_shortcode("[the_ad id='1180']"); // Show Petoskey Area CVB ad
+ break;
+ case 4: // Antrim County
+ case 17: // Grand Traverse County
+ case 38: // Leelanau County
+ echo do_shortcode("[the_ad id='1186']"); // Show Traverse City CVB ad
+ break;
+ default:
+ break; // No ads
+ }
+ break;
+ }
+ echo "<br>";
}
\ No newline at end of file
<main class="page-inside">
<div id="content-wrapper">
- <div id="top-ad-container" class="row">
- <?php
- // If a city is searched for, if it is one of certain cities, display the ad for that city.
- // If it is not one of those cities check the county associated with the city searched for
- // Otherwise, If a city is not searched for, check for the county that is searched for,
- // then display the ad for that county
- $county = 0;$city = 0;
- if (isset($_REQUEST['cities'][0]) && $_REQUEST['cities'][0] > 0) {
- $county = apply_filters("get_county_by_city", $_REQUEST['cities'][0]);
- $city = $_REQUEST['cities'][0];
- } else if (isset($_REQUEST['counties'][0]) && $_REQUEST['counties'][0] > 0) {
- $county = $_REQUEST['counties'][0];
- }
- switch ($city) { // Find by city first, specific list given by client
- case 37: // Gaylord County
- echo do_shortcode("[the_ad id='1182']"); // Gaylord Area CVB
- break;
- case 89: // Petoskey County
- echo do_shortcode("[the_ad id='1180']"); // Petoskey Area CVB
- break;
- case 106: // Traverse City County
- echo do_shortcode("[the_ad id='1186']"); // Traverse City CVB
- break;
- default: // If a specific city override is not found, look at the county
- switch ($county) {
- case 40: // Crawford County
- case 2: // Montmorency County
- case 8: // Otsego County
- echo do_shortcode("[the_ad id='1182']"); // Gaylord Area CVB
- break;
- case 9: // Charlevoix County
- case 13: // Emmet County
- echo do_shortcode("[the_ad id='1180']"); // Petoskey Area CVB
- break;
- case 4: // Antrim County
- case 17: // Grand Traverse County
- case 38: // Leelanau County
- echo do_shortcode("[the_ad id='1186']"); // Traverse City CVB
- break;
- default:
- break; // No ads
- }
- break;
- }
- ?>
- </div>
<div class="row">
<?php if(function_exists('bcn_display') && !is_front_page())
{
}
?>
</div>
+ <div id="top-ad-container" class="row">
+ <?php
+ // Member detail page runs a separate function because it does not use $_REQUEST
+ if (!is_member()) {
+ $county = 0;$city = 0;$destination = 0;
+ if (isset($_REQUEST['categories'][0]) && $_REQUEST['categories'][0] > 0) {
+ $destination = $_REQUEST['categories'][0];
+ } else if (isset($_REQUEST['cities'][0]) && $_REQUEST['cities'][0] > 0) {
+ $county = apply_filters("get_county_by_city", $_REQUEST['cities'][0]);
+ $city = $_REQUEST['cities'][0];
+ } else if (isset($_REQUEST['counties'][0]) && $_REQUEST['counties'][0] > 0) {
+ $county = $_REQUEST['counties'][0];
+ }
+ // If a destination is searched for, display the ad for the city corresponding to that destination
+ // (e.g. Petoskey Area destination => Petoskey city => Petoskey Area CVB ad)
+ // If a city is searched for, if it is one of certain cities, display the ad for that city.
+ // If it is not one of those cities check the county associated with the city searched for
+ // Otherwise, If a city is not searched for, check for the county that is searched for,
+ // then display the ad for that county
+ display_top_ads($city, $county, $destination);
+ }
+ ?>
+ </div>
<div class="row">
<?php get_template_part('parts/main-content');?>
<!--