Only show Popular Tags if there are any tags to show
authorLaury GvR <laury@gaslightmedia.com>
Fri, 2 Feb 2018 17:37:46 +0000 (12:37 -0500)
committerLaury GvR <laury@gaslightmedia.com>
Fri, 2 Feb 2018 17:37:46 +0000 (12:37 -0500)
Sidebar for news pages has a Popular Tags section which shows any
tags of posts posted in the last 30 days. If there are no tags, the
section would still show. This has been changed to only show the
section if there are any tags.

sidebar.php

index 8b3566b..e98da3e 100644 (file)
@@ -14,76 +14,78 @@ if ( ! is_active_sidebar( 'sidebar-1' ) ) {
 
 <aside id="secondary" class="widget-area" role="complementary">
     
-        <?php if (get_page_template_slug( $post->ID ) === "members-only-template.php") {  // Members only ?>
+        <?php if ( get_page_template_slug( $post->ID ) === "members-only-template.php" && current_user_can("glm_members_member") ) {  // Members only ?>
             <section class="widget sidebar">
                 <h2 class="widget-title">Members Only Area</h2>
                 <div id="members-only-menu-side" class="widget-container members-only">
-                    <?php if (current_user_can("glm_members_member")) { ?>
-                        <ul>
-                        <?php glm_members_only_menu(); ?>
-                        </ul>
-                    <?php } ?>
+                    <ul>
+                    <?php glm_members_only_menu(); ?>
+                    </ul>
                 </div>
             </section>
+            <?php echo the_ad_group(3057); // Members only ad group ?>
+        <?php } else { ?>
+            <?php if (! dynamic_sidebar('sidebar-top-ad')):endif; ?>
         <?php } ?>
-       <?php if (! dynamic_sidebar('sidebar-top-ad')):endif; ?>
        <section class="widget sidebar">
 
-               <h2 class="widget-title">Explore Posts</h2>
+            <h2 class="widget-title">Explore Posts</h2>
 
-               <div class="widget-container explore-posts">
+            <div class="widget-container explore-posts">
 
-                       <ul>
-                               <li><a href="<?php echo get_tag_link(108); ?>">What's Hot This Month</a></li>
-                               <li><a href="<?php echo get_category_link(8); ?>">Things to Do</a></li>
-                               <li><a href="<?php echo get_tag_link(847); ?>">West Michigan Trails</a></li>
-                               <li><a href="<?php echo get_tag_link(25); ?>">West Michigan Kids</a></li>
-                               <li><a href="<?php echo get_tag_link(38); ?>">Free in West Michigan</a></li>
-                               <li><a href="<?php echo get_permalink(34); ?>">All Posts</a></li>
+                <ul>
+                    <li><a href="<?php echo get_tag_link(108); ?>">What's Hot This Month</a></li>
+                    <li><a href="<?php echo get_category_link(8); ?>">Things to Do</a></li>
+                    <li><a href="<?php echo get_tag_link(847); ?>">West Michigan Trails</a></li>
+                    <li><a href="<?php echo get_tag_link(25); ?>">West Michigan Kids</a></li>
+                    <li><a href="<?php echo get_tag_link(38); ?>">Free in West Michigan</a></li>
+                    <li><a href="<?php echo get_permalink(34); ?>">All Posts</a></li>
 
-                       </ul>
+                </ul>
 
-               </div>
+            </div>
 
        </section>
 
        <?php dynamic_sidebar( 'sidebar-1' ); ?>
         <?php if ( is_blog() ) { ?>
-            <section class="widget sidebar">
-                <!-- Only show for blog-related pages -->
-                    <h2 class="widget-title">Popular Tags</h2>
-
-                    <div class="widget-container popular-tags">
+            <?php                                     
+                global $wpdb;
+                $term_ids = $wpdb->get_col("
+                    SELECT DISTINCT term_taxonomy_id FROM $wpdb->term_relationships
+                    INNER JOIN $wpdb->posts ON $wpdb->posts.ID = object_id
+                    WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= $wpdb->posts.post_date");
+
+                if(count($term_ids) > 0){
+                    $tags = get_tags(array(
+                        'orderby' => 'random',
+                        'order'   => 'DESC',
+                        'number'  => 20,
+                        'include' => $term_ids,
+                    ));?>
+                    <?php if ( count( $tags ) > 0 ) { ?>
+                    <section class="widget sidebar">
+                        <!-- Only show for blog-related pages -->
+                        <h2 class="widget-title">Popular Tags</h2>
+
+                        <div class="widget-container popular-tags">
 
                             <ul>
-                                    <?php
-                                    global $wpdb;
-                                    $term_ids = $wpdb->get_col("
-       SELECT DISTINCT term_taxonomy_id FROM $wpdb->term_relationships
-          INNER JOIN $wpdb->posts ON $wpdb->posts.ID = object_id
-          WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= $wpdb->posts.post_date");
-
-                                    if(count($term_ids) > 0){
-
-                                            $tags = get_tags(array(
-                                                            'orderby' => 'random',
-                                                            'order'   => 'DESC',
-                                                            'number'  => 20,
-                                                            'include' => $term_ids,
-                                            ));
-                                            foreach ( (array) $tags as $tag ) {
-                                                    echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . '</a></li>';
-                                            }
+                                <?php
+                                    foreach ( (array) $tags as $tag ) {
+                                            echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . '</a></li>';
                                     }
-                                    ?>
+                                ?>
                             </ul>
 
                             <div style="clear: both;"></div>
 
-                    </div>
+                        </div>
 
-            </section>
-        <?php } ?>
+                    </section>
+                    <?php } ?>
+                <?php } ?>
+            <?php } ?>
 
        <?php dynamic_sidebar( 'sidebar-signup' ); ?>