From: Steve Sutton Date: Thu, 29 Oct 2015 12:53:57 +0000 (-0400) Subject: Adding link to post X-Git-Tag: v1.2.3^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=748389f4a5ff079ee5611606c059df53685e435c;p=WP-Plugins%2Fglm-blocks.git Adding link to post Made new select list just for the post. The page one I kept because it was showing the hierarchy for the pages. I did restrict them to only show pages or post that are published. --- diff --git a/js/glm-blocks.js b/js/glm-blocks.js index 23392a6..541bdf4 100644 --- a/js/glm-blocks.js +++ b/js/glm-blocks.js @@ -9,6 +9,13 @@ jQuery(function($){ $("input[name=glm_block_url]").filter('input[value=page]').attr('checked', false); } }); + $("#glm_block_post").change(function(){ + if($("#glm_block_post").val()) { + $("input[name=glm_block_url]").filter('input[value=post]').attr('checked', true); + } else { + $("input[name=glm_block_url]").filter('input[value=post]').attr('checked', false); + } + }); $("#glm_block_ext_url").change(function(){ if($("#glm_block_ext_url").val()) { $("input[name=glm_block_url]").filter('input[value=url]').attr('checked', true); diff --git a/models/block.php b/models/block.php index e613a75..f27de36 100644 --- a/models/block.php +++ b/models/block.php @@ -148,6 +148,9 @@ class glm_models_block $glm_block_page = ($post) ? get_post_meta($post->ID, 'glm_block_page', true) : ''; + $glm_block_post = ($post) + ? get_post_meta($post->ID, 'glm_block_post', true) + : ''; include $this->pluginDirName . 'views/admin/metaBoxes.php'; } @@ -181,6 +184,7 @@ class glm_models_block update_post_meta($post->ID, 'glm_block_ext_url', $_POST['glm_block_ext_url']); update_post_meta($post->ID, 'glm_block_page', $_POST['glm_block_page']); + update_post_meta($post->ID, 'glm_block_post', $_POST['glm_block_post']); } /** @@ -202,16 +206,21 @@ class glm_models_block foreach ($blocks as $block) { $block->externalUrl = false; $custom = get_post_custom($block->ID); - if ($custom['glm_block_url'][0] == 'page') { + switch ($custom['glm_block_url'][0]) { + case 'page': $block->url = get_permalink($custom['glm_block_page'][0]); - } - if ($custom['glm_block_url'][0] == 'url') { + 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('/^http:\/\//', $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') diff --git a/views/admin/metaBoxes.php b/views/admin/metaBoxes.php index 7631d4f..8adef7b 100644 --- a/views/admin/metaBoxes.php +++ b/views/admin/metaBoxes.php @@ -19,7 +19,7 @@ > - + 1, 'name' => 'glm_block_page', 'id' => 'glm_block_page', - 'show_option_none' => 'None' + 'show_option_none' => 'None', + 'post_status' => 'publish', + 'post_type' => 'page' ) ); ?> +
+> + + + 'post', + 'suppress_filters' => true, + 'update_post_term_cache' => false, + 'update_post_meta_cache' => false, + 'post_status' => 'publish', + 'order' => 'DESC', + 'orderby' => 'date', + 'posts_per_page' => -1, + ); + $get_posts = new WP_Query; + $posts = $get_posts->query( $query ); + $results = array(); + if ( ! $get_posts->post_count ) { + return $results; + } + foreach ( $posts as $post ) { + if ( 'post' == $post->post_type ) { + $info = mysql2date( __( 'Y/m/d' ), $post->post_date ); + } else { + continue; + } + $results[] = array( + 'ID' => $post->ID, + 'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ), + 'permalink' => get_permalink( $post->ID ), + 'info' => $info, + ); + } + return $results; +} +?>