Content Blocks (Custom Post Widget) - Version 1.2.1

Version Description

The widget title now uses $before_title and $after_title to generate the appropriate tags to display it on the page. Hat tip: Etienne Proust.

=

Download this release

Release Info

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

Code changes from version 1.1.1 to 1.2.1

Files changed (3) hide show
  1. custom-post-widget.php +22 -6
  2. readme.txt +22 -8
  3. screenshot-2.png +0 -0
custom-post-widget.php CHANGED
@@ -3,11 +3,11 @@
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.1.1
7
  Author: Johan van der Wijk
8
  Author URI: http://www.vanderwijk.com
9
 
10
- Release notes: 1.0 First version
11
 
12
  */
13
 
@@ -23,11 +23,12 @@ class custom_post_widget extends WP_Widget
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&showposts=-1');
32
  if ( have_posts() ) : while ( have_posts() ) : the_post();
33
  $currentID = get_the_ID();
@@ -42,13 +43,21 @@ class custom_post_widget extends WP_Widget
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
 
@@ -58,12 +67,19 @@ class custom_post_widget extends WP_Widget
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();
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.2
7
  Author: Johan van der Wijk
8
  Author URI: http://www.vanderwijk.com
9
 
10
+ Release notes: 1.2 Added the option for displaying the post title
11
 
12
  */
13
 
23
  function form($instance)
24
  {
25
  $custom_post_id = esc_attr($instance['custom_post_id']);
26
+ $show_custom_post_title = isset($instance['show_custom_post_title ']) ? $instance['show_custom_post_title '] : true;
27
 
28
  ?>
29
  <p>
30
  <label for="<?php echo $this->get_field_id('custom_post_id'); ?>"> <?php echo __('Content Block to Display:') ?>
31
+ <select class="widefat" id="<?php echo $this->get_field_id('custom_post_id'); ?>" name="<?php echo $this->get_field_name('custom_post_id'); ?>">
32
  <?php query_posts('post_type=content_block&orderby=ID&order=ASC&showposts=-1');
33
  if ( have_posts() ) : while ( have_posts() ) : the_post();
34
  $currentID = get_the_ID();
43
  wp_reset_query(); ?>
44
  </select>
45
  </label>
46
+ </p>
47
+ <p>
48
+ <input class="checkbox" type="checkbox" <?php checked( (bool) $instance['show_custom_post_title'], true ); ?> id="<?php echo $this->get_field_id( 'show_custom_post_title' ); ?>" name="<?php echo $this->get_field_name( 'show_custom_post_title' ); ?>" />
49
+ <label for="<?php echo $this->get_field_id( 'show_custom_post_title' ); ?>"><?php echo __('Show Post Title') ?></label>
50
+ </p>
51
+
52
+ <?php
53
  }
54
 
55
  function update($new_instance, $old_instance)
56
  {
57
  $instance = $old_instance;
58
  $instance['custom_post_id'] = strip_tags($new_instance['custom_post_id']);
59
+ $instance['show_custom_post_title'] = $new_instance['show_custom_post_title'];
60
+
61
  return $instance;
62
  }
63
 
67
 
68
  $custom_post_id = ( $instance['custom_post_id'] != '' ) ? esc_attr($instance['custom_post_id']) : 'Zoeken';
69
 
70
+ /* Our variables from the widget settings. */
71
+ $show_custom_post_title = isset( $instance['show_custom_post_title'] ) ? $instance['show_custom_post_title'] : false;
72
+
73
+ /* Before widget (defined by themes). */
74
+ echo $before_widget;
75
 
76
  // Output the query to find the custom post
77
  query_posts( 'post_type=content_block&p=' . $custom_post_id );
78
  while (have_posts()) : the_post();
79
+
80
+ if ( $show_custom_post_title )
81
+ echo the_title($before_title, $after_title); // This is the line that displays the title
82
+
83
  echo the_content();
84
  endwhile;
85
  wp_reset_query();
readme.txt CHANGED
@@ -1,24 +1,29 @@
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.1.1
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.
@@ -29,7 +34,7 @@ To add content to a widget, drag it to the required position in the sidebar and
29
  1. First you will have to upload the plugin to the `/wp-content/plugins/` folder.
30
  2. Then activate the plugin in the plugin panel.
31
  You will see that a new custom post type has been added called Content Block.
32
- 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.
33
  4. Go to 'Appearance' > 'Widgets' and drag the Content Block widget to the required position in the sidebar.
34
  5. Select a Content Block from the drop-down list.
35
  6. Click save.
@@ -49,12 +54,21 @@ It is recommended to install the Widget Logic plugin, this will give you complet
49
  = 1.0 =
50
  First release
51
 
 
 
 
52
  = 1.1.1 =
53
  Added showposts=-1 to the post query to display more than 10 custom posts in the widget configuration select box.
54
 
 
 
 
 
 
 
55
  == Upgrade Notice ==
56
 
57
- = 1.0 =
58
- First release
59
 
60
 
1
  === Custom Post Widget ===
2
  Contributors: vanderwijk
3
+ Author URI: http://www.vanderwijk.com/
4
+ Donate link: http://www.vanderwijk.com/wordpress/support/
5
  Tags: custom post, widget, sidebar
6
+ Requires at least: 2.9.2
7
+ Tested up to: 3.0.3
8
+ Stable tag: 1.2.1
9
 
10
  This plugin enables you to display the content of a custom post type called Content Block in a sidebar widget.
11
 
12
  == Description ==
13
 
14
+ The Custom Post Widget allows you to display the contents of a specific custom post in a widget.
15
+
16
  Even though you could use the text widget that comes with the default WordPress install, this plugin has some clear benefits:
17
 
 
18
  * 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.
19
+ * It enables users to use the WYSIWYG editor for editing the content and adding images
20
 
21
  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.
22
 
23
  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.
24
 
25
+ You can find more information about this plugin and a screencast video which shows the plugin in action on the [plugin homepage](http://www.vanderwijk.com/services/web-design/wordpress-custom-post-widget/).
26
+
27
  == Screenshots ==
28
 
29
  1. After activating the plugin a new post type called 'Content Blocks' is added.
34
  1. First you will have to upload the plugin to the `/wp-content/plugins/` folder.
35
  2. Then activate the plugin in the plugin panel.
36
  You will see that a new custom post type has been added called Content Block.
37
+ 3. Type some content for the widget. You can choose to either use the title to describe the of the content on the page, or to display it. Check 'Show Post Title' to display the title on the page.
38
  4. Go to 'Appearance' > 'Widgets' and drag the Content Block widget to the required position in the sidebar.
39
  5. Select a Content Block from the drop-down list.
40
  6. Click save.
54
  = 1.0 =
55
  First release
56
 
57
+ = 1.1 =
58
+ Fixed screenshots for plugin directory
59
+
60
  = 1.1.1 =
61
  Added showposts=-1 to the post query to display more than 10 custom posts in the widget configuration select box.
62
 
63
+ = 1.2 =
64
+ Added a checkbox in the widget to make it possible to show the custom post title in the widget area
65
+
66
+ = 1.2.1 =
67
+ The widget title now uses $before_title and $after_title to generate the appropriate tags to display it on the page. Hat tip: Etienne Proust.
68
+
69
  == Upgrade Notice ==
70
 
71
+ = 1.1.1 =
72
+ Now supports more than 10 custom posts in the select box. Note that after upgrading you might have to save the widget state before the correct posts are being displayed.
73
 
74
 
screenshot-2.png CHANGED
Binary file