Post tag check for entity templates
authorLaury GvR <laury@gaslightmedia.com>
Wed, 16 Aug 2017 16:46:38 +0000 (12:46 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Wed, 16 Aug 2017 16:46:38 +0000 (12:46 -0400)
Post tags are now checked to determine which entity template to use.
Blog home now shows only posts with relevant tags.

index.php
parts/blog-content-area.php
parts/blog-text.php
sidebar.php

index d47b1f7..835dfad 100644 (file)
--- a/index.php
+++ b/index.php
@@ -8,13 +8,23 @@
         } else if ( get_entity_template() ) {
             $GLOBALS['entity_page_slug'] = get_entity_template();
         } else {
-            $GLOBALS['entity_page_slug'] = 'default';
+            if (has_tag('government', $post)) {
+                $GLOBALS['entity_page_slug'] = 'government';
+            } else if (has_tag('chamber-of-commerce', $post)) {
+                $GLOBALS['entity_page_slug'] = 'chamber-of-commerce';
+            } else if (has_tag('edc', $post)) {
+                $GLOBALS['entity_page_slug'] = 'edc';
+            } else if (has_tag('convention-visitors-bureau', $post)) {
+                $GLOBALS['entity_page_slug'] = 'convention-visitors-bureau';
+            } else {
+                $GLOBALS['entity_page_slug'] = 'default';
+            }
         }
         // get_entity_template returns current page slug if current page is entity page
         //  returns parent entity page slug if child of entity page
         //  returns false if top-level non-entity
 
-    ?>
+        ?>
     <body class="<?php echo $GLOBALS['entity_page_slug'] ?>-entity">
         <div class="off-canvas-wrapper">
             <div class="off-canvas-wrapper-inner" data-off-canvas-wrapper>
                         include "sections/front-page.php";
                     } else {
                         include "sections/header.php";
-                        if (is_home()) {
+                        if (is_home() || is_page($GLOBALS['entity_page_slug']."-news")) {
                             include "sections/blog-home.php";
-                        }
-                        if (is_archive()) {
+                        } else if (is_archive()) {
                             include "sections/blog-archive.php";
-                        }
-                        if (is_single()) {
+                        } else if (is_single()) {
                             include "sections/blog-single.php";
-                        }
-                        if (is_search()) {
+                        } else if (is_search()) {
                             include "sections/search.php";
-                        }
-                        if (is_page() && !is_front_page()) {
+                        } else if (is_page() && !is_front_page()) {
                             if(is_entity_landing_page()) {
                                 include __DIR__.'/sections/entity-landing.php';
                             } else {
index 66c0dd3..bcdcfbe 100644 (file)
@@ -1,5 +1,7 @@
         <div id="blog-posts-over" class="small-12 medium-9 columns">
-            <?php if(have_posts()) : while(have_posts()): the_post();?>
+            <?php $tag_query = new WP_Query( 'tag='.$GLOBALS['entity_page_slug'] ); ?>
+            <?php echo $GLOBALS['entity_page_slug']; ?>
+            <?php if($tag_query->have_posts()) : while($tag_query->have_posts()): $tag_query->the_post();?>
             <div class="row content blog-posts-container">
               <!--  <div class="small-11 small-centered columns"> -->
                 <?php $thumbnail = get_the_post_thumbnail($post->ID, 'blog-feed-front'); ?>
index 342dfa1..27bfe00 100644 (file)
@@ -1,14 +1,14 @@
                                                 <article id="<?php the_ID()?>" <?php post_class()?>>
                                                     <header class="entry-header">
-                                                        <h1 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h1>
+                                                        <h1 class="entry-title"><a href="<?php the_permalink(); ?>?entity_template=<?php echo $GLOBALS['entity_page_slug'];?>"><?php the_title();?></a></h1>
                                                         <?php if ( has_post_thumbnail() ):?>
-                                                                 <?php if (get_post_type( $post ) != "ai1ec_event") { ?>
-                                                        <div class="featured-image-wrap"><?php the_post_thumbnail("large"); ?></div>
-                                                        <?php } ?>
+                                                            <?php if (get_post_type( $post ) != "ai1ec_event") { ?>
+                                                                <div class="featured-image-wrap"><?php the_post_thumbnail("large"); ?></div>
+                                                            <?php } ?>
                                                         <?php endif; ?>
                                                         <span class="meta date">Posted on <?php the_time('F jS, Y') ?></span>
                                                         <?php get_template_part('parts/share-this'); ?>
                                                     </header>
-                                                       
+
                                                     <?php echo the_content(); ?>
                                                 </article>
\ No newline at end of file
index ba76897..fe719cb 100644 (file)
@@ -1,20 +1,3 @@
-<?php 
-switch ($GLOBALS['entity_page_slug']) {
-    case 'government':
-        $sidebar_class = 'government';
-        break;
-    case 'chamber-of-commerce':
-        $sidebar_class = 'chamber';
-        break;
-    case 'convention-visitors-bureau':
-        $sidebar_class = 'cvb';
-        break;
-    case 'edc':
-        $sidebar_class = 'default';
-        break;
-    default:
-        break;
-} ?>
 <div class="row opensearchserver.ignore">
     <div class="small-12 columns text-center medium-text-left">
         <div class="sidebar-share small-12 columns show-for-large-up">