Frontier Post – Taxonomy Example
On this site, I have implemented 2 Taxonomies: Article Types & Topics to classify the posts on this site. The categories are used for the plugins.
I have added the taxonomies to the site using a plugin (see code below), but this code can also be be added to functions.php in you child-theme. I created the first taxonomy using generatewp.com for the second one, I just used copy/paste and then search/replace 🙂
Code:
<?php
/*
Plugin Name: Frontier Pluginsite
Plugin URI: http://wpfrontier.com/
Description: Article type and Topics taxonomies to setup website for your plugin
Author: finnj
Version: 1.0.0
Author URI: hhttp://wpfrontier.com/
*/
// define constants
define('FRONTIER_PLUGINSITE_VERSION', "1.0.0");
//*************************************************************************
// Set options on activation
//*************************************************************************
function frontier_pluginsite_set_defaults ()
{
}
register_activation_hook( __FILE__ , 'frontier_pluginsite_set_defaults');
//*************************************************************************
// Setup Article type taxonomy
//*************************************************************************
function frontier_tax_article_type() {
$labels = array(
'name' => _x( 'Article types', 'Taxonomy General Name', 'frontier-article-type' ),
'singular_name' => _x( 'Article type', 'Taxonomy Singular Name', 'frontier-article-type' ),
'menu_name' => __( 'Article types', 'frontier-article-type' ),
'all_items' => __( 'All Article types', 'frontier-article-type' ),
'parent_item' => __( 'Parent Article type', 'frontier-article-type' ),
'parent_item_colon' => __( 'Parent Article type:', 'frontier-article-type' ),
'new_item_name' => __( 'New Article type Name', 'frontier-article-type' ),
'add_new_item' => __( 'Add New Article type', 'frontier-article-type' ),
'edit_item' => __( 'Edit Article type', 'frontier-article-type' ),
'update_item' => __( 'Update Article type', 'frontier-article-type' ),
'separate_items_with_commas' => __( 'Separate Article types with commas', 'frontier-article-type' ),
'search_items' => __( 'Search Article types', 'frontier-article-type' ),
'add_or_remove_items' => __( 'Add or remove Article types', 'frontier-article-type' ),
'choose_from_most_used' => __( 'Choose from the most used Article types', 'frontier-article-type' ),
'not_found' => __( 'Not Found', 'frontier-article-type' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'update_count_callback' => '_update_post_term_count',
'rewrite' => array( 'slug' => 'article-type' )
);
register_taxonomy( 'article-type', array( 'post' ), $args );
}
// Hook into the 'init' action
add_action( 'init', 'frontier_tax_article_type', 0 );
//*************************************************************************
// Setup Topics taxonomy
//*************************************************************************
function frontier_tax_topics() {
$labels = array(
'name' => _x( 'Topics', 'Taxonomy General Name', 'frontier-topics' ),
'singular_name' => _x( 'Topic', 'Taxonomy Singular Name', 'frontier-topics' ),
'menu_name' => __( 'Topics', 'frontier-topics' ),
'all_items' => __( 'All Topics', 'frontier-topics' ),
'parent_item' => __( 'Parent Topic', 'frontier-topics' ),
'parent_item_colon' => __( 'Parent Topic:', 'frontier-topics' ),
'new_item_name' => __( 'New Topic Name', 'frontier-topics' ),
'add_new_item' => __( 'Add New Topic', 'frontier-topics' ),
'edit_item' => __( 'Edit Topic', 'frontier-topics' ),
'update_item' => __( 'Update Topic', 'frontier-topics' ),
'separate_items_with_commas' => __( 'Separate Topics with commas', 'frontier-topics' ),
'search_items' => __( 'Search Topics', 'frontier-topics' ),
'add_or_remove_items' => __( 'Add or remove Topics', 'frontier-topics' ),
'choose_from_most_used' => __( 'Choose from the most used Topics', 'frontier-topics' ),
'not_found' => __( 'Not Found', 'frontier-topics' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'update_count_callback' => '_update_post_term_count',
'rewrite' => array( 'slug' => 'topics' )
);
register_taxonomy( 'topics', array( 'post' ), $args );
}
// Hook into the 'init' action
add_action( 'init', 'frontier_tax_topics', 0 );
//*************************************************************************
// Translation
//*************************************************************************
function frontier_pluginsite_translation()
{
load_plugin_textdomain('frontier-pluginsite', false, dirname( plugin_basename( __FILE__ ) ).'/language');
}
add_action('plugins_loaded', 'frontier_pluginsite_translation');
//*************************************************************************
// End plugin
//*************************************************************************
?>
Comments
Frontier Post – Taxonomy Example — No Comments
HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>