Only show 'popular tags' sidebar section on blog pages
authorLaury GvR <laury@gaslightmedia.com>
Fri, 2 Feb 2018 16:34:17 +0000 (11:34 -0500)
committerLaury GvR <laury@gaslightmedia.com>
Fri, 2 Feb 2018 16:34:17 +0000 (11:34 -0500)
functions.php
sidebar.php

index fa6ede3..a82d0f2 100644 (file)
@@ -335,4 +335,11 @@ function restore_slider_behavior( $settings ) {
   $settings['infinite'] = 'true'; 
   return $settings;
 }
-add_filter( 'advanced-ads-slider-settings', 'restore_slider_behavior' );
\ No newline at end of file
+add_filter( 'advanced-ads-slider-settings', 'restore_slider_behavior' );
+
+// More concise way to check for blog-related pages
+function is_blog () {
+        global  $post;
+        $posttype = get_post_type($post );
+        return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post')  ) ? true : false ;
+  }
\ No newline at end of file
index 5c4c214..8b3566b 100644 (file)
@@ -48,41 +48,42 @@ if ( ! is_active_sidebar( 'sidebar-1' ) ) {
        </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">
+
+                            <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>';
+                                            }
+                                    }
+                                    ?>
+                            </ul>
+
+                            <div style="clear: both;"></div>
+
+                    </div>
 
-       <section class="widget sidebar">
-
-               <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>';
-                                       }
-                               }
-                               ?>
-                       </ul>
-
-                       <div style="clear: both;"></div>
-
-               </div>
-
-       </section>
+            </section>
+        <?php } ?>
 
        <?php dynamic_sidebar( 'sidebar-signup' ); ?>