Make WordPress Core

Ticket #16736: test_plugin.php

File test_plugin.php, 3.3 KB (added by valentinas, 15 years ago)

dummy custom post type and custom taxonomy plugin. code taken from codex

Line 
1<?php
2/*
3Plugin name: test plugin
4*/
5
6//following code taken from http://codex.wordpress.org/Function_Reference/register_post_type#Example
7add_action('init', 'codex_custom_init');
8function codex_custom_init()
9{
10 $labels = array(
11 'name' => _x('Books', 'post type general name'),
12 'singular_name' => _x('Book', 'post type singular name'),
13 'add_new' => _x('Add New', 'book'),
14 'add_new_item' => __('Add New Book'),
15 'edit_item' => __('Edit Book'),
16 'new_item' => __('New Book'),
17 'view_item' => __('View Book'),
18 'search_items' => __('Search Books'),
19 'not_found' => __('No books found'),
20 'not_found_in_trash' => __('No books found in Trash'),
21 'parent_item_colon' => '',
22 'menu_name' => 'Books'
23
24 );
25 $args = array(
26 'labels' => $labels,
27 'public' => true,
28 'publicly_queryable' => true,
29 'show_ui' => true,
30 'show_in_menu' => true,
31 'query_var' => true,
32 'rewrite' => true,
33 'capability_type' => 'post',
34 'has_archive' => true,
35 'hierarchical' => false,
36 'menu_position' => null,
37 'supports' => array('title','editor','author','thumbnail','excerpt','comments')
38 );
39 register_post_type('book',$args);
40}
41
42
43//following code taken from http://codex.wordpress.org/Function_Reference/register_taxonomy#Example
44
45//hook into the init action and call create_book_taxonomies when it fires
46add_action( 'init', 'create_book_taxonomies', 0 );
47
48//create two taxonomies, genres and writers for the post type "book"
49function create_book_taxonomies()
50{
51 // Add new taxonomy, make it hierarchical (like categories)
52 $labels = array(
53 'name' => _x( 'Genres', 'taxonomy general name' ),
54 'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
55 'search_items' => __( 'Search Genres' ),
56 'all_items' => __( 'All Genres' ),
57 'parent_item' => __( 'Parent Genre' ),
58 'parent_item_colon' => __( 'Parent Genre:' ),
59 'edit_item' => __( 'Edit Genre' ),
60 'update_item' => __( 'Update Genre' ),
61 'add_new_item' => __( 'Add New Genre' ),
62 'new_item_name' => __( 'New Genre Name' ),
63 'menu_name' => __( 'Genre' ),
64 );
65
66 register_taxonomy('genre',array('book'), array(
67 'hierarchical' => true,
68 'labels' => $labels,
69 'show_ui' => true,
70 'query_var' => true,
71 'rewrite' => array( 'slug' => 'genre' ),
72 ));
73
74 // Add new taxonomy, NOT hierarchical (like tags)
75 $labels = array(
76 'name' => _x( 'Writers', 'taxonomy general name' ),
77 'singular_name' => _x( 'Writer', 'taxonomy singular name' ),
78 'search_items' => __( 'Search Writers' ),
79 'popular_items' => __( 'Popular Writers' ),
80 'all_items' => __( 'All Writers' ),
81 'parent_item' => null,
82 'parent_item_colon' => null,
83 'edit_item' => __( 'Edit Writer' ),
84 'update_item' => __( 'Update Writer' ),
85 'add_new_item' => __( 'Add New Writer' ),
86 'new_item_name' => __( 'New Writer Name' ),
87 'separate_items_with_commas' => __( 'Separate writers with commas' ),
88 'add_or_remove_items' => __( 'Add or remove writers' ),
89 'choose_from_most_used' => __( 'Choose from the most used writers' ),
90 'menu_name' => __( 'Writers' ),
91 );
92
93 register_taxonomy('writer','book',array(
94 'hierarchical' => false,
95 'labels' => $labels,
96 'show_ui' => true,
97 'query_var' => true,
98 'rewrite' => array( 'slug' => 'writer' ),
99 ));
100}
101
102?>