From 73c30567e884555e5ce4f768b9f7f6705035e7b1 Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Thu, 9 Nov 2017 15:52:38 -0500 Subject: [PATCH] Member ads show on member detail, and destinations Ads are now showing on member detail pages based on which city, or else county, is assigned to it. Ads on the member list page are now including possible ads for Destinations, which utilise the same ads set for the corresponding cities. For both, the function display_top_ads and filter get_county_by_city are created. --- functions.php | 67 ++++++++++++++++++ glm-member-db/views/front/members/detail.html | 16 +++++ sections/interior-page.php | 69 +++++++------------ 3 files changed, 106 insertions(+), 46 deletions(-) diff --git a/functions.php b/functions.php index 0d980ec..89474f6 100644 --- a/functions.php +++ b/functions.php @@ -72,6 +72,16 @@ add_filter('glm-member-db-front-search-query', function( $queryParts ) { }); 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 " @@ -439,4 +449,61 @@ if (!function_exists('write_log')) { } } } +} +/* + * 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 "
"; } \ No newline at end of file diff --git a/glm-member-db/views/front/members/detail.html b/glm-member-db/views/front/members/detail.html index 47f8d73..eca5520 100644 --- a/glm-member-db/views/front/members/detail.html +++ b/glm-member-db/views/front/members/detail.html @@ -1,3 +1,19 @@ +
+ + {if $member.city} + {$memberCity = $member.city} + {$memberCounty = apply_filters("get_county_by_city", $member.city)} + {else} + {$memberCity = 0} + {if $member.county} + {$memberCounty = $member.county} + {else} + {$memberCounty = 0} + {/if} + {/if} + + {display_top_ads($memberCity, $memberCounty)} +
{include file='front/members/header.html'} {apply_filters('glm-member-db-front-members-detail-pageTop', '', $member.id)} diff --git a/sections/interior-page.php b/sections/interior-page.php index 18fcff9..2d339f1 100644 --- a/sections/interior-page.php +++ b/sections/interior-page.php @@ -1,51 +1,5 @@
-
- 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; - } - ?> -
+
+ 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); + } + ?> +