Member ads show on member detail, and destinations
authorLaury GvR <laury@gaslightmedia.com>
Thu, 9 Nov 2017 20:52:38 +0000 (15:52 -0500)
committerLaury GvR <laury@gaslightmedia.com>
Thu, 9 Nov 2017 20:52:38 +0000 (15:52 -0500)
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
glm-member-db/views/front/members/detail.html
sections/interior-page.php

index 0d980ec..89474f6 100644 (file)
@@ -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 "<br>";
 }
\ No newline at end of file
index 47f8d73..eca5520 100644 (file)
@@ -1,3 +1,19 @@
+<div id="top-ad-container" class="row">
+    
+    {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}
+    <!-- This function also takes a third parameter of "destination" which we may eventually use -->
+    {display_top_ads($memberCity, $memberCounty)}
+</div>
 {include file='front/members/header.html'}
 
 {apply_filters('glm-member-db-front-members-detail-pageTop', '', $member.id)}
index 18fcff9..2d339f1 100644 (file)
@@ -1,51 +1,5 @@
                     <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');?>
                 <!--