Content Blocks (Custom Post Widget) - Version 1.0

Version Description

First release

=

Download this release

Release Info

Developer vanderwijk
Plugin Icon 128x128 Content Blocks (Custom Post Widget)
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (4) hide show
  1. custom-post-widget.php +134 -0
  2. readme.txt +58 -0
  3. screenshot-1.PNG +0 -0
  4. screenshot-2.PNG +0 -0
custom-post-widget.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Custom Post Widget
4
+ Plugin URI: http://www.vanderwijk.com/services/web-design/wordpress-custom-post-widget/
5
+ Description: Show the content of a custom post of the type 'content_block' in a widget.
6
+ Version: 1.0
7
+ Author: Johan van der Wijk
8
+ Author URI: http://www.vanderwijk.com
9
+
10
+ Release notes: 1.0 First version
11
+
12
+ */
13
+
14
+ // First create the widget for the admin panel
15
+ class custom_post_widget extends WP_Widget
16
+ {
17
+ function custom_post_widget()
18
+ {
19
+ $widget_ops = array('description' => __('Displays custom post content in a widget'));
20
+ $this->WP_Widget('custom_post_widget', __('Content Block'), $widget_ops);
21
+ }
22
+
23
+ function form($instance)
24
+ {
25
+ $custom_post_id = esc_attr($instance['custom_post_id']);
26
+
27
+ ?>
28
+ <p>
29
+ <label for="<?php echo $this->get_field_id('custom_post_id'); ?>"> <?php echo __('Content Block to Display:') ?>
30
+ <select id="<?php echo $this->get_field_id('custom_post_id'); ?>" name="<?php echo $this->get_field_name('custom_post_id'); ?>">
31
+ <?php query_posts('post_type=content_block&orderby=ID&order=ASC');
32
+ if ( have_posts() ) : while ( have_posts() ) : the_post();
33
+ $currentID = get_the_ID();
34
+ if($currentID == $custom_post_id)
35
+ $extra = 'selected';
36
+ else
37
+ $extra = '';
38
+ echo '<option value="'.$currentID.'" '.$extra.'>'.get_the_title().'</option>';
39
+ endwhile; else:
40
+ echo '<option value="empty">No content blocks available</option>';
41
+ endif;
42
+ wp_reset_query(); ?>
43
+ </select>
44
+ </label>
45
+ </p><?php
46
+ }
47
+
48
+ function update($new_instance, $old_instance)
49
+ {
50
+ $instance = $old_instance;
51
+ $instance['custom_post_id'] = strip_tags($new_instance['custom_post_id']);
52
+ return $instance;
53
+ }
54
+
55
+ function widget($args, $instance)
56
+ {
57
+ extract($args);
58
+
59
+ $custom_post_id = ( $instance['custom_post_id'] != '' ) ? esc_attr($instance['custom_post_id']) : 'Zoeken';
60
+
61
+ // Output title & $before_widget
62
+ echo $title . $before_widget;
63
+
64
+ // Output the query to find the custom post
65
+ query_posts( 'post_type=content_block&p=' . $custom_post_id );
66
+ while (have_posts()) : the_post();
67
+ echo the_content();
68
+ endwhile;
69
+ wp_reset_query();
70
+
71
+ // Output $after_widget
72
+ echo $after_widget;
73
+ }
74
+ }
75
+ add_action('widgets_init', create_function('', 'return register_widget("custom_post_widget");'));
76
+
77
+ // Create the Content Block custom post type
78
+
79
+ add_action('init', 'my_content_block_post_type_init');
80
+
81
+ function my_content_block_post_type_init()
82
+ {
83
+ $labels = array(
84
+ 'name' => _x('Content Blocks', 'post type general name'),
85
+ 'singular_name' => _x('Content Block', 'post type singular name'),
86
+ 'add_new' => _x('Add Content Block', 'block'),
87
+ 'add_new_item' => __('Add New Content Block'),
88
+ 'edit_item' => __('Edit Content Block'),
89
+ 'new_item' => __('New Content Block'),
90
+ 'view_item' => __('View Content Block'),
91
+ 'search_items' => __('Search Content Blocks'),
92
+ 'not_found' => __('No Content Blocks Found'),
93
+ 'not_found_in_trash' => __('No Content Blocks found in Trash'),
94
+ 'parent_item_colon' => ''
95
+ );
96
+ $options = array(
97
+ 'labels' => $labels,
98
+ 'public' => false,
99
+ 'publicly_queryable' => false,
100
+ 'exclude_from_search' => true,
101
+ 'show_ui' => true,
102
+ 'query_var' => true,
103
+ 'rewrite' => true,
104
+ 'capability_type' => 'post',
105
+ 'hierarchical' => false,
106
+ 'menu_position' => null,
107
+ 'supports' => array('title','editor','revisions','thumbnail')
108
+ );
109
+ register_post_type('content_block',$options);
110
+ }
111
+
112
+ add_filter('post_updated_messages', 'content_block_messages');
113
+
114
+ function content_block_messages( $messages ) {
115
+
116
+ $messages['content_block'] = array(
117
+ 0 => '',
118
+ 1 => sprintf( __('Content Block updated. <a href="%s">View Content Block</a>'), esc_url( get_permalink($post_ID) ) ),
119
+ 2 => __('Custom field updated.'),
120
+ 3 => __('Custom field deleted.'),
121
+ 4 => __('Content Block updated.'),
122
+ 5 => isset($_GET['revision']) ? sprintf( __('Content Block restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
123
+ 6 => sprintf( __('Content Block published. <a href="%s">View Content Block</a>'), esc_url( get_permalink($post_ID) ) ),
124
+ 7 => __('Block saved.'),
125
+ 8 => sprintf( __('Content Block submitted. <a target="_blank" href="%s">Preview Content Block</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
126
+ 9 => sprintf( __('Content Block scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview block</a>'),
127
+ date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
128
+ 10 => sprintf( __('Content Block draft updated. <a target="_blank" href="%s">Preview Content Block</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
129
+ );
130
+
131
+ return $messages;
132
+ }
133
+
134
+ ?>
readme.txt ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Custom Post Widget ===
2
+ Contributors: vanderwijk
3
+ Donate link: http://www.vanderwijk.com/
4
+ Tags: custom post, widget, sidebar
5
+ Requires at least: 2.9
6
+ Tested up to: 3.0.1
7
+ Stable tag: 1.0
8
+
9
+ This plugin enables you to display the content of a custom post type called Content Block in a sidebar widget.
10
+
11
+ == Description ==
12
+
13
+ Even though you could use the text widget that comes with the default WordPress install, this plugin has some clear benefits:
14
+
15
+ * It enables users to use the WYSIWYG editor for editing the content and adding images
16
+ * If you are using widgets to display content on various areas of your template, this content can only be edited by users with administrator access. If you would like editors to modify the widget content, you can use this plugin to provide them access to the custom posts that provide the content for the widget areas.
17
+
18
+ This plugin creates a 'content_block' custom post type. The title is never displayed, use this to describe the position of the widget on the page. Note that these content blocks can only be displayed in the context of the page. I have added 'public' => false to the custom post type which means that it is not accessible outside the page context.
19
+
20
+ To add content to a widget, drag it to the required position in the sidebar and select the title of the custom post in the widget configuration.
21
+
22
+ == Screenshots ==
23
+
24
+ 1. After activating the plugin a new post type called 'Content Blocks' is added.
25
+ 2. The widget has a select box to choose the content block.
26
+
27
+
28
+ == Installation ==
29
+
30
+ 1. First you will have to upload the plugin to the plugin folder.
31
+ 2. Then activate the plugin in the plugin panel.
32
+ You will see that a new custom post type has been added called Content Block.
33
+ 3. Type some content for the widget. The title can be used to describe the position of the content on the page, It will not be displayed in the actual widget.
34
+ 4. Go to 'Appearance' > 'Widgets' and drag the Content Block widget to the required position in the sidebar.
35
+ 5. Select a Content Block from the drop-down list.
36
+ 6. Click save.
37
+
38
+ == Frequently Asked Questions ==
39
+
40
+ = Why can't I use the default text-widget? =
41
+
42
+ Of course you can always use the default text widget, but if you prefer to use the WYSIWYG editor or if you have multiple editors and you don't want to give them administrator rights, it is recommended to use this plugin.
43
+
44
+ = How can I show the content bock on a specific page? =
45
+
46
+ It is recommended to install the Widget Logic plugin, this will give you complete flexibility on widget placement.
47
+
48
+ == Changelog ==
49
+
50
+ = 1.0 =
51
+ First release
52
+
53
+ == Upgrade Notice ==
54
+
55
+ = 1.0 =
56
+ First release
57
+
58
+
screenshot-1.PNG ADDED
Binary file
screenshot-2.PNG ADDED
Binary file