Post Tags and Categories for Pages - Version 1.1

Version Description

  • made it a class based plugin
  • cleaned up TODO notes that I have no reference for now
  • brought it in to line better with WordPress coding standards
Download this release

Release Info

Developer curtismchale
Plugin Icon wp plugin Post Tags and Categories for Pages
Version 1.1
Comparing to
See all releases

Code changes from version 1.0 to 1.1

Files changed (2) hide show
  1. post-tag.php +53 -71
  2. readme.txt +8 -2
post-tag.php CHANGED
@@ -3,96 +3,78 @@
3
  Plugin Name: Post Tags and Categories for Pages
4
  Plugin URI: http://wpthemetutorial.com/plugins/post-tags-and-categories-for-pages/
5
  Description: Simply adds the stock Categories and Post Tags to your Pages.
6
- Version: 1.0
7
  Author: WP Theme Tutorial
8
  Author URI: http://wpthemetutotial.com/about/
9
  License: GNU General Public License v2.0
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
  */
12
 
13
- /**
14
- * todo give user the option to add categories and tags - on by default
15
- * todo give user option to display tags and categories on archive pages - on by default
16
- * TODO add categories to the end of pages
17
- * TODO add the tags to the end of pages
18
- */
19
 
20
- /**
21
- * Registers the taxonomy terms for the post type
22
- *
23
- * @since 1.0
24
- *
25
- * @uses register_taxonomy_for_object_type
26
- */
27
- function ptcfp_taxonomies_for_pages() {
28
- register_taxonomy_for_object_type( 'post_tag', 'page' );
29
- register_taxonomy_for_object_type( 'category', 'page' );
30
- }
31
- add_action( 'init', 'ptcfp_taxonomies_for_pages' );
32
 
33
  /**
34
- * Includes the tags in archive pages
35
- *
36
- * Modifies the query object to include pages
37
- * as well as posts in the items to be returned
38
- * on archive pages
39
  *
40
  * @since 1.0
41
  */
42
- function ptcfp_tags_archives( $wp_query ) {
43
-
44
- if ( $wp_query->get( 'tag' ) )
45
- $wp_query->set( 'post_type', 'any' );
46
 
47
- /* I just leave this here if I need to debug stuff */
48
- //ptcfp_print_r( $wp_query );
49
 
50
- }
 
 
 
 
 
 
 
 
 
 
51
 
52
- /**
53
- * Includes the categories in archive pages
54
- *
55
- * Modifies the query object to include pages
56
- * as well as posts in the items to be returned
57
- * on archive pages
58
- *
59
- * @since 1.0
60
- */
61
- function ptcfp_category_archives( $wp_query ) {
62
 
63
- if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) )
64
- $wp_query->set( 'post_type', 'any' );
65
 
66
- /* I just leave this here if I need to debug stuff */
67
- //ptcfp_print_r( $wp_query );
68
 
69
- }
 
 
 
 
 
 
 
 
 
70
 
71
- /**
72
- * Want to make sure that these query modifications don't
73
- * show on the admin side or we're going to get pages and
74
- * posts mixed in together when we click on a term
75
- * in the admin
76
- *
77
- * @since 1.0
78
- */
79
- if( !is_admin() ) {
80
- add_action( 'pre_get_posts', 'ptcfp_category_archives' );
81
- add_action( 'pre_get_posts', 'ptcfp_tags_archives' );
82
- }
83
 
84
- /**
85
- * Produces print_r inside <pre>
86
- *
87
- * @param string $data The variable we want to print
88
- *
89
- * @since 1.0
90
- */
91
- function ptcfp_print_r( $data ) {
92
 
93
- echo "<pre>";
94
- print_r($data);
95
- echo "</pre>";
96
 
97
- }
98
- ?>
3
  Plugin Name: Post Tags and Categories for Pages
4
  Plugin URI: http://wpthemetutorial.com/plugins/post-tags-and-categories-for-pages/
5
  Description: Simply adds the stock Categories and Post Tags to your Pages.
6
+ Version: 1.1
7
  Author: WP Theme Tutorial
8
  Author URI: http://wpthemetutotial.com/about/
9
  License: GNU General Public License v2.0
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
  */
12
 
13
+ class PTCFP{
 
 
 
 
 
14
 
15
+ function __construct(){
16
+
17
+ add_action( 'init', array( $this, 'taxonomies_for_pages' ) );
 
 
 
 
 
 
 
 
 
18
 
19
  /**
20
+ * Want to make sure that these query modifications don't
21
+ * show on the admin side or we're going to get pages and
22
+ * posts mixed in together when we click on a term
23
+ * in the admin
 
24
  *
25
  * @since 1.0
26
  */
27
+ if ( ! is_admin() ) {
28
+ add_action( 'pre_get_posts', array( $this, 'category_archives' ) );
29
+ add_action( 'pre_get_posts', array( $this, 'tags_archives' ) );
30
+ } // ! is_admin
31
 
32
+ } // __construct
 
33
 
34
+ /**
35
+ * Registers the taxonomy terms for the post type
36
+ *
37
+ * @since 1.0
38
+ *
39
+ * @uses register_taxonomy_for_object_type
40
+ */
41
+ function taxonomies_for_pages() {
42
+ register_taxonomy_for_object_type( 'post_tag', 'page' );
43
+ register_taxonomy_for_object_type( 'category', 'page' );
44
+ } // taxonomies_for_pages
45
 
46
+ /**
47
+ * Includes the tags in archive pages
48
+ *
49
+ * Modifies the query object to include pages
50
+ * as well as posts in the items to be returned
51
+ * on archive pages
52
+ *
53
+ * @since 1.0
54
+ */
55
+ function tags_archives( $wp_query ) {
56
 
57
+ if ( $wp_query->get( 'tag' ) )
58
+ $wp_query->set( 'post_type', 'any' );
59
 
60
+ } // tags_archives
 
61
 
62
+ /**
63
+ * Includes the categories in archive pages
64
+ *
65
+ * Modifies the query object to include pages
66
+ * as well as posts in the items to be returned
67
+ * on archive pages
68
+ *
69
+ * @since 1.0
70
+ */
71
+ function category_archives( $wp_query ) {
72
 
73
+ if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) )
74
+ $wp_query->set( 'post_type', 'any' );
 
 
 
 
 
 
 
 
 
 
75
 
76
+ } // category_archives
 
 
 
 
 
 
 
77
 
78
+ } // PTCFP
 
 
79
 
80
+ $ptcfp = new PTCFP();
 
readme.txt CHANGED
@@ -3,8 +3,8 @@
3
  Contributors: Curtis McHale
4
  Tags: wp, tags, categories, pages
5
  Requires at least: 3.0
6
- Tested up to: 3.4
7
- Stable tag: 1.0
8
 
9
  Adds the built in WordPress categories and tags to your pages.
10
 
@@ -23,6 +23,12 @@ folder.
23
 
24
  == Changelog ==
25
 
 
 
 
 
 
 
26
  = 1.0 =
27
 
28
  - relesed on WordPress repository
3
  Contributors: Curtis McHale
4
  Tags: wp, tags, categories, pages
5
  Requires at least: 3.0
6
+ Tested up to: 3.5
7
+ Stable tag: 1.1
8
 
9
  Adds the built in WordPress categories and tags to your pages.
10
 
23
 
24
  == Changelog ==
25
 
26
+ = 1.1 =
27
+
28
+ - made it a class based plugin
29
+ - cleaned up TODO notes that I have no reference for now
30
+ - brought it in to line better with WordPress coding standards
31
+
32
  = 1.0 =
33
 
34
  - relesed on WordPress repository