$("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);
$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';
}
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']);
}
/**
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')
<?php if ($glm_block_url == 'page') {
echo 'checked';
}; ?>>
-<label for="my_meta_box_post_type">Internal link: </label>
+<label for="my_meta_box_post_type">Internal Page: </label>
<?php
wp_dropdown_pages(
array(
'echo' => 1,
'name' => 'glm_block_page',
'id' => 'glm_block_page',
- 'show_option_none' => 'None'
+ 'show_option_none' => 'None',
+ 'post_status' => 'publish',
+ 'post_type' => 'page'
)
);
?>
</select>
+<br>
+<input type="radio" name="glm_block_url" value="post"
+<?php if ($glm_block_url == 'post') {
+ echo 'checked';
+}; ?>>
+<label for="my_meta_box_post_type">Internal Post: </label>
+<select id="glm_block_post" name="glm_block_post">
+<option value="">None</option>
+<?php
+$glmPosts = glm_blocks_get_posts();
+foreach ($glmPosts as $post) {
+ echo '<option value="' . $post['ID'] . '"';
+ if ($post['ID'] == $glm_block_post) {
+ echo ' selected';
+ }
+ echo '>' . $post['title'] . '</option>';
+}
+?>
+</select>
+<?php
+function glm_blocks_get_posts() {
+ $query = array(
+ 'post_type' => '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;
+}
+?>