adding shortcode for landing page blocks output
authorAnthony Talarico <talarico@gaslightmedia.com>
Thu, 29 Nov 2018 20:03:21 +0000 (15:03 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Thu, 29 Nov 2018 20:03:21 +0000 (15:03 -0500)
glm-blocks.php

index 1fde095..20907d7 100644 (file)
@@ -53,3 +53,33 @@ if (!function_exists('fetch_all_glm_blocks')) {
         return $frontController->fetchAllBlocks($catId);
     }
 }
+function landing_page_blocks( $atts )
+{
+    $out = '';
+    extract(shortcode_atts(
+        array('category' => '-1'), $atts, 'glm-blocks')
+    );
+    if(function_exists('fetch_all_glm_blocks')):
+        $category = filter_var($atts['category'], FILTER_VALIDATE_INT);
+        $blocks = fetch_all_glm_blocks($category);
+        $out .= '<ul id="quick-sub_pages" class="small-block-grid-1 medium-block-grid-3">';
+        foreach ($blocks as $block):
+            $post_image_id = get_post_thumbnail_id($block->ID);
+            $thumbnail = wp_get_attachment_image_src( $post_image_id, 'landing_page');
+            $out .= '<li class="small-text-center medium-text-left landing-item">';
+            if($block->url):
+                $out .= '<a href="'.$block->url.'"'.(($block->externalUrl)? ' target="_blank"':'').'>';
+            endif;
+            $out .= '<img src="'.$thumbnail[0].'"/>';
+            $out .= '<div class="land-page-block-image" style="background: url('.$thumbnail.');"></div>';
+            $out .= '<h5>'.$block->post_title.'</h5>';
+            if($block->url):
+                $out .= '</a>';
+            endif;
+            $out .= '</li>';
+        endforeach;
+        $out .= '</ul>';
+    endif;
+    return $out;
+}
+add_shortcode('glm-blocks', 'landing_page_blocks');
\ No newline at end of file