|
<?php # -*- coding: utf-8 -*- |
|
/* |
|
Plugin Name: Custom Taxonomy Quote Author |
|
Plugin URI: https://gist.github.com/996608 |
|
Description: Creates a custom taxonomy <code>Quote Author</code> with an URI <code>/qa/author-name/</code> |
|
Version: 1.0 |
|
Required: 3.1 |
|
Author: Thomas Scholz |
|
Author URI: http://toscho.de |
|
License: GPL |
|
*/ |
|
! defined( 'ABSPATH' ) and exit; |
|
|
|
add_action( 'after_setup_theme', 'register_quote_author' ); |
|
|
|
register_activation_hook( __FILE__, 'qua_flush' ); |
|
register_deactivation_hook( __FILE__, 'qua_flush' ); |
|
|
|
/** |
|
* Registers the taxonomy 'Quote Author'. |
|
* |
|
* To list the authors with links in your theme use |
|
* @link http://codex.wordpress.org/Function_Reference/get_the_term_list |
|
* <code>print get_the_term_list( get_the_ID(), 'quoteauthor' );</code> |
|
* |
|
* @link http://codex.wordpress.org/Function_Reference/register_taxonomy |
|
* @return void |
|
*/ |
|
function register_quote_author() |
|
{ |
|
register_taxonomy( |
|
// Internal name |
|
'quoteauthor' |
|
// Post types the taxonomy applies to. |
|
// The attachment field is not very nice, just a simple input field. |
|
// You may tweak that. |
|
, array ( 'post', 'attachment' ) |
|
// Visible labels |
|
, array ( |
|
'labels' => array ( |
|
'name' => 'Quote Authors' |
|
, 'menu_name' => 'Quote Authors' |
|
, 'singular_name' => 'Quote Author' |
|
, 'search_items' => 'Search Quote Authors' |
|
, 'popular_items' => 'Popular Quote Authors' |
|
, 'all_items' => 'All Quote Authors' |
|
, 'edit_item' => 'Edit Quote Author' |
|
, 'update_item' => 'Update Quote Author' |
|
, 'add_new_item' => 'Add Quote Author' |
|
, 'new_item_name' => 'New name for Quote Author' |
|
, 'separate_items_with_commas' => 'Separate Quote Authors by comma' |
|
, 'add_or_remove_items' => 'Add or remove Quote Authors' |
|
, 'choose_from_most_used' => 'Choose from most quoted authors' |
|
) |
|
// Most important parameter. :) |
|
, 'public' => TRUE |
|
// Available in custom menus. |
|
, 'show_in_nav_menus' => TRUE |
|
// Standard box. |
|
, 'show_ui' => TRUE |
|
// Clickable list of popular authors. |
|
, 'show_tagcloud' => TRUE |
|
// URI |
|
, 'rewrite' => array ( |
|
'slug' => 'qa' |
|
) |
|
// If you want to use WP_Query. |
|
, 'query_var' => 'qa' |
|
) |
|
); |
|
} |
|
/** |
|
* Tells WordPress to rebuild the rewrite rules to include our custom URIS. |
|
* |
|
* @return void |
|
*/ |
|
function qua_flush() |
|
{ |
|
// The current instance of the class WP_Rewrite. |
|
global $wp_rewrite; |
|
$wp_rewrite->flush_rules(); |
|
} |