Custom Post Template - Version 1.4

Version Description

Download this release

Release Info

Developer simonwheatley
Plugin Icon wp plugin Custom Post Template
Version 1.4
Comparing to
See all releases

Code changes from version 1.3 to 1.4

custom-post-templates.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Custom Post Templates
4
  Plugin URI: http://wordpress.org/extend/plugins/custom-post-template/
5
  Description: Provides a drop-down to select different templates for posts from the post edit screen. The templates are defined similarly to page templates, and will replace single.php for the specified post.
6
  Author: Simon Wheatley
7
- Version: 1.3
8
  Author URI: http://simonwheatley.co.uk/wordpress/
9
  */
10
 
@@ -45,7 +45,10 @@ class CustomPostTemplates extends CustomPostTemplates_Plugin
45
  $this->tpl_meta_key = 'custom_post_template';
46
  // Init hooks and all that
47
  $this->register_plugin ( 'custom-post-templates', __FILE__ );
48
- $this->add_meta_box( 'select_post_template', __( 'Post Template', 'custom-post-templates' ), 'select_post_template', 'post', 'side', 'default' );
 
 
 
49
  $this->add_action( 'save_post' );
50
  $this->add_filter( 'single_template', 'filter_single_template' );
51
  $this->add_filter( 'body_class' );
@@ -56,6 +59,22 @@ class CustomPostTemplates extends CustomPostTemplates_Plugin
56
  * *******************
57
  */
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  /**
60
  * Hooks the WP body_class function to add a class to single posts using a post template.
61
  *
@@ -149,12 +168,17 @@ class CustomPostTemplates extends CustomPostTemplates_Plugin
149
  $post_templates = array();
150
 
151
  if ( is_array( $templates ) ) {
 
152
  $base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) );
153
 
154
  foreach ( $templates as $template ) {
 
 
 
 
155
  $basename = str_replace($base, '', $template);
156
 
157
- // don't allow template files in subdirectories
158
  if ( false !== strpos($basename, '/') )
159
  continue;
160
 
4
  Plugin URI: http://wordpress.org/extend/plugins/custom-post-template/
5
  Description: Provides a drop-down to select different templates for posts from the post edit screen. The templates are defined similarly to page templates, and will replace single.php for the specified post.
6
  Author: Simon Wheatley
7
+ Version: 1.4
8
  Author URI: http://simonwheatley.co.uk/wordpress/
9
  */
10
 
45
  $this->tpl_meta_key = 'custom_post_template';
46
  // Init hooks and all that
47
  $this->register_plugin ( 'custom-post-templates', __FILE__ );
48
+ // NOTE TO PEOPLE WANTING TO USE CUSTOM POST TYPES:
49
+ // Don't edit this file, instead use the cpt_post_types filter. See the plugin description
50
+ // for more information. Thank you and good night.
51
+ $this->add_action( 'admin_init' );
52
  $this->add_action( 'save_post' );
53
  $this->add_filter( 'single_template', 'filter_single_template' );
54
  $this->add_filter( 'body_class' );
59
  * *******************
60
  */
61
 
62
+ /**
63
+ * Hooks the WP admin_init action to add metaboxes
64
+ *
65
+ * @param
66
+ * @return void
67
+ * @author Simon Wheatley
68
+ **/
69
+ public function admin_init() {
70
+ // NOTE TO PEOPLE WANTING TO USE CUSTOM POST TYPES:
71
+ // Don't edit this file, instead use the cpt_post_types filter. See the plugin description
72
+ // for more information. Thank you and good night.
73
+ $post_types = apply_filters( 'cpt_post_types', array( 'post' ) );
74
+ foreach ( $post_types as $post_type )
75
+ $this->add_meta_box( 'select_post_template', __( 'Post Template', 'custom-post-templates' ), 'select_post_template', $post_type, 'side', 'default' );
76
+ }
77
+
78
  /**
79
  * Hooks the WP body_class function to add a class to single posts using a post template.
80
  *
168
  $post_templates = array();
169
 
170
  if ( is_array( $templates ) ) {
171
+ $theme_root = dirname(get_theme_root());
172
  $base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) );
173
 
174
  foreach ( $templates as $template ) {
175
+ // Some setups seem to pass the templates without the theme root,
176
+ // so we conditionally prepend the root for the theme files.
177
+ if ( stripos( $template, $theme_root ) === false )
178
+ $template = $theme_root . $template;
179
  $basename = str_replace($base, '', $template);
180
 
181
+ // Don't allow template files in subdirectories
182
  if ( false !== strpos($basename, '/') )
183
  continue;
184
 
readme.txt CHANGED
@@ -3,15 +3,13 @@ Contributors: simonwheatley
3
  Donate link: http://www.simonwheatley.co.uk/wordpress/
4
  Tags: post, template, theme
5
  Requires at least: 2.9
6
- Tested up to: 3.0
7
- Stable tag: 1.3
8
 
9
  Provides a drop-down to select different templates for posts from the post edit screen. The templates replace single.php for the specified post.
10
 
11
  == Description ==
12
 
13
- **This plugin requires PHP5 (see Other Notes > PHP4 for more).**
14
-
15
  Provides a drop-down to select different templates for posts from the post edit screen. The templates are defined similarly to page templates, and will replace single.php for the specified post. This plugin will NOT switch the templates for the different posts in a listing page, e.g. a date or category archive, it will only affect the template used for single posts (i.e. you can choose a template which is not single.php).
16
 
17
  Post templates, as far as this plugin is concerned, are configured similarly to [page templates](http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates) in that they have a particular style of PHP comment at the top of them. Each post template must contain the following, or similar, at the top:
@@ -23,13 +21,28 @@ Template Name Posts: Snarfer
23
  ?>
24
  </code>
25
 
26
- Note that *page* templates use "_Template Name:_", whereas *post* templates use "_Template Name Posts:_".
 
 
27
 
28
- Plugin initially produced on behalf of [Words & Pictures](http://www.wordsandpics.co.uk/).
29
 
30
- Is this plugin lacking a feature you want? I'm happy to discuss ideas, or to accept offers of feature sponsorship: [contact me](http://www.simonwheatley.co.uk/contact-me/) and we can have a chat.
31
 
32
- Any issues: [contact me](http://www.simonwheatley.co.uk/contact-me/).
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  == Installation ==
35
 
@@ -42,15 +55,12 @@ The plugin is simple to install:
42
  1. Upload your post template files (see the Description for details on configuring these), and choose them through the new menu
43
  1. Give yourself a pat on the back
44
 
45
- == PHP4 ==
46
-
47
- Many of my plugin now require at least PHP5. I know that WordPress officially supports PHP4, but I don't. PHP4 is a mess and makes coding a lot less efficient, and when you're releasing stuff for free these things matter. PHP5 has been out for several years now and is fully production ready, as well as being naturally more secure and performant.
48
-
49
- If you're still running PHP4, I strongly suggest you talk to your hosting company about upgrading your servers. All reputable hosting companies should offer PHP5 as well as PHP4.
50
 
51
- Right, that's it. Grump over. ;)
52
 
53
- == Change Log ==
 
54
 
55
  = v1.3 2010/06/17 =
56
 
@@ -60,10 +70,6 @@ This release includes the facility for Custom Post Template to be translated int
60
 
61
  Sorry it took so long.
62
 
63
- Best regards,
64
-
65
- Simon
66
-
67
  * ENHANCEMENT: Now works with child themes, hat-tip Kathy
68
  * LOCALISATION: Now ready for localisation!
69
 
@@ -80,6 +86,7 @@ Simon
80
 
81
  * BUGFIX: Theme templates now come with a complete filepath, so no need to add WP_CONTENT_DIR constant to the beginning.
82
  * ENHANCEMENT: Metabox now shows up on the side, under the publish box... where you'd expect.
 
83
 
84
  = v0.9b 2008/11/26 =
85
 
3
  Donate link: http://www.simonwheatley.co.uk/wordpress/
4
  Tags: post, template, theme
5
  Requires at least: 2.9
6
+ Tested up to: 3.2.1
7
+ Stable tag: 1.4
8
 
9
  Provides a drop-down to select different templates for posts from the post edit screen. The templates replace single.php for the specified post.
10
 
11
  == Description ==
12
 
 
 
13
  Provides a drop-down to select different templates for posts from the post edit screen. The templates are defined similarly to page templates, and will replace single.php for the specified post. This plugin will NOT switch the templates for the different posts in a listing page, e.g. a date or category archive, it will only affect the template used for single posts (i.e. you can choose a template which is not single.php).
14
 
15
  Post templates, as far as this plugin is concerned, are configured similarly to [page templates](http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates) in that they have a particular style of PHP comment at the top of them. Each post template must contain the following, or similar, at the top:
21
  ?>
22
  </code>
23
 
24
+ First note: *Page* templates use "_Template Name:_", whereas *post* templates use "_Template Name Posts:_".
25
+
26
+ Second note: You *must* have the custom post template files in your theme in the same directory/folder as your index.php template file, *not* in a sub-directory/sub-folder.
27
 
28
+ == Developers ==
29
 
30
+ If you want to implement the custom post *templates* on a custom post *type*, you can use the `cpt_post_types` filter, here's an example below of adding the custom post template selector and metabox to the "Movie" and "Actor" custom post types. This code can be added to a plugin or to the `functions.php` file in your theme.
31
 
32
+ `
33
+ /**
34
+ * Hooks the WP cpt_post_types filter
35
+ *
36
+ * @param array $post_types An array of post type names that the templates be used by
37
+ * @return array The array of post type names that the templates be used by
38
+ **/
39
+ function my_cpt_post_types( $post_types ) {
40
+ $post_types[] = 'movie';
41
+ $post_types[] = 'actor';
42
+ return $post_types;
43
+ }
44
+ add_filter( 'cpt_post_types', 'my_cpt_post_types' );
45
+ `
46
 
47
  == Installation ==
48
 
55
  1. Upload your post template files (see the Description for details on configuring these), and choose them through the new menu
56
  1. Give yourself a pat on the back
57
 
58
+ == Change Log ==
 
 
 
 
59
 
60
+ = v1.4 2011/08/14 =
61
 
62
+ * Added a filter, `cpt_post_types`, so people can choose which post types this plugin shows the UI for
63
+ * Linked to WP.org, not my site, for documentation (quicker to load)
64
 
65
  = v1.3 2010/06/17 =
66
 
70
 
71
  Sorry it took so long.
72
 
 
 
 
 
73
  * ENHANCEMENT: Now works with child themes, hat-tip Kathy
74
  * LOCALISATION: Now ready for localisation!
75
 
86
 
87
  * BUGFIX: Theme templates now come with a complete filepath, so no need to add WP_CONTENT_DIR constant to the beginning.
88
  * ENHANCEMENT: Metabox now shows up on the side, under the publish box... where you'd expect.
89
+ * Plugin initially produced on behalf of [Words & Pictures](http://www.wordsandpics.co.uk/).
90
 
91
  = v0.9b 2008/11/26 =
92
 
view/admin/select_post_template.php CHANGED
@@ -22,10 +22,10 @@
22
  <?php } ?>
23
  </select>
24
 
25
- <p><?php printf( __( 'This theme has some <a href="%s" target="_blank">custom post templates</a> that you can use to on individual posts, you can select one for this post using the drop down above.', 'custom-post-templates' ), 'http://simonwheatley.co.uk/wordpress/custom-post-template/' ); ?></p>
26
 
27
  <?php else : ?>
28
 
29
- <p><?php printf( __( 'This theme has no available <a href="%s" target="_blank">custom post templates</a>.', 'custom-post-templates' ), 'http://simonwheatley.co.uk/wordpress/custom-post-template/' ); ?></p>
30
 
31
  <?php endif; ?>
22
  <?php } ?>
23
  </select>
24
 
25
+ <p><?php printf( __( 'This theme has some <a href="%s" target="_blank">custom post templates</a> that you can use to on individual posts, you can select one for this post using the drop down above.', 'custom-post-templates' ), 'http://wordpress.org/extend/plugins/custom-post-template/' ); ?></p>
26
 
27
  <?php else : ?>
28
 
29
+ <p><?php printf( __( 'This theme has no available <a href="%s" target="_blank">custom post templates</a>.', 'custom-post-templates' ), 'http://wordpress.org/extend/plugins/custom-post-template/' ); ?></p>
30
 
31
  <?php endif; ?>