From: Anthony Talarico Date: Fri, 30 Nov 2018 16:12:47 +0000 (-0500) Subject: adding new function to blocks that allows for slug to be passed instead of cat id X-Git-Tag: v1.6.2^2~6 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=9dd63424b3fd135bc50670a5d30007208dcc0fc6;p=WP-Plugins%2Fglm-blocks.git adding new function to blocks that allows for slug to be passed instead of cat id --- diff --git a/controllers/front.php b/controllers/front.php index 124e761..6e7cdfd 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -49,4 +49,16 @@ class glm_blocks_front $block = new glm_models_block($this->pluginDirName); return $block->fetchAllBlocks($catID); } + /** + * Fetches the blocks into an array + * + * Now you can control how the block is output + * + * @return array + */ + public function fetch_blocks_by_slug($cat) + { + $block = new glm_models_block($this->pluginDirName); + return $block->fetch_blocks_by_slug($cat); + } } diff --git a/glm-blocks.php b/glm-blocks.php index a65f534..1625e65 100644 --- a/glm-blocks.php +++ b/glm-blocks.php @@ -53,14 +53,15 @@ if (!function_exists('fetch_all_glm_blocks')) { return $frontController->fetchAllBlocks($catId); } } -function landing_page_blocks( $atts ) -{ +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 .= '
'; $count = 0; @@ -88,4 +89,50 @@ function landing_page_blocks( $atts ) endif; return $out; } +if (!function_exists('fetch_blocks_by_slug')) { + function fetch_blocks_by_slug($cat) + { + $frontController = new glm_blocks_front( + plugin_dir_path(__FILE__) + ); + return $frontController->fetch_blocks_by_slug($cat); + } +} +function action_item_blocks( $atts ){ + + $out = ''; + extract(shortcode_atts( + array('category' => '-1'), $atts, 'glm-blocks') + ); + if(function_exists('fetch_blocks_by_slug')): + $category = filter_var($atts['category'], FILTER_VALIDATE_INT); + fetch_blocks_by_slug($category); + $blocks = fetch_blocks_by_slug($category); + $out .= '
'; + $count = 0; + 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 .= '
'; + endif; + return $out; +} +add_shortcode('glm-blocks-action-items', 'action_item_blocks'); add_shortcode('glm-blocks', 'landing_page_blocks'); \ No newline at end of file diff --git a/models/block.php b/models/block.php index 3183e85..24b4672 100644 --- a/models/block.php +++ b/models/block.php @@ -261,7 +261,69 @@ class glm_models_block } return $blocks; } + /** + * fetchAllBlocks + * + * @access public + * @return void + */ + public function fetch_blocks_by_slug($cat) + { + global $wpdb, $wp; + $parent = array( + 'name' => $cat, + 'post_type' => GLM_BLOCK_POST_TYPE, + 'post_status' => 'publish', + 'numberposts' => 1 + ); + $block_parent = get_posts($parent)[0]; + $args = array( + 'posts_per_page' => -1, + 'post_type' => GLM_BLOCK_POST_TYPE, + 'orderby' => 'menu_order post_title', + 'order' => 'asc' + ); + $args['post_parent'] = $block_parent->ID; + + $blocks = get_posts($args); + foreach ($blocks as $block) { + $block->externalUrl = false; + $custom = get_post_custom($block->ID); + if (isset($custom['glm_block_url'])) { + switch ($custom['glm_block_url'][0]) { + case 'event': + if ( defined( 'GLM_MEMBERS_EVENTS_PLUGIN_NAME' ) ) { + $event = apply_filters('glm-member-db-events-get-event-data', $custom['glm_block_event'][0]); + if ( $event ) { + $block->url = home_url() . '/event-detail/' . $event['name_slug'] . '/'; + } + } else if ( defined( 'AI1EC_PATH' ) ) { + $block->url = get_permalink($custom['glm_block_event'][0]); + } + break; + case 'page': + $block->url = get_permalink($custom['glm_block_page'][0]); + break; + case 'post': + $block->url = get_permalink($custom['glm_block_post'][0]); + break; + case 'url': + if ($custom['glm_block_ext_url'][0] != '') { + $block->url = (preg_match('/^https?:\/\//', $custom['glm_block_ext_url'][0])) + ? $custom['glm_block_ext_url'][0] + : 'http://' . $custom['glm_block_ext_url'][0]; + $block->externalUrl = true; + } + break; + } + } + $block->thumbnail = get_the_post_thumbnail( + $block->ID, GLM_BLOCK_POST_TYPE, array('class' => 'aligncenter') + ); + } + return $blocks; + } /** * displayBlocks *