Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action('init', 'projects_cpt');
- function projects_cpt() {
- $args = array(
- 'hierarchical' => true,
- 'rewrite' => array('slug' => 'projects'),
- 'show_in_nav_menus' => true,
- 'labels' => $labels
- );
- register_taxonomy('projectscategory', 'projects', $args);
- unset($labels);
- unset($args);
- $labels = array(
- 'name' => 'Projects',
- 'singular_name' => 'Project',
- 'add_new' => 'Add New',
- 'add_new_item' => 'Add New Project',
- 'edit_item' => 'Edit Project',
- 'new_item' => 'New Project',
- 'all_items' => 'All Projects',
- 'view_item' => 'View Project',
- 'search_items' => 'Search Projects',
- 'not_found' => 'No projects found',
- 'not_found_in_trash' => 'No projects found in Trash',
- 'parent_item_colon' => '',
- 'menu_name' => 'Projects'
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'query_var' => true,
- 'taxonomies' => array('projectstype' ),
- 'rewrite' => array('slug' => 'projects/%projectscategory%', 'with_front' => false),
- //Adding custom rewrite tag
- 'capability_type' => 'post',
- 'has_archive' => 'projectsarchives',
- 'hierarchical' => false,
- 'menu_position' => null,
- 'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt'),
- );
- register_post_type('projects', $args);
- $labels = array(
- 'name' => 'Projects Categories',
- 'singular_name' => 'Projects',
- 'search_items' => 'Search Projects Categories',
- 'all_items' => 'All Projects Categories',
- 'parent_item' => 'Parent Project Category',
- 'parent_item_colon' => 'Parent Project Category:',
- 'edit_item' => 'Edit Project Category',
- 'update_item' => 'Update Project Category',
- 'add_new_item' => 'Add New Project Category',
- 'new_item_name' => 'New Project Category',
- );
- }
- ?>
- <?php
- add_filter('post_type_link', 'projectcategory_permalink_structure', 10, 4);
- function projectcategory_permalink_structure($post_link, $post, $leavename,
- $sample) {
- if (false !== strpos($post_link, '%projectscategory%')) {
- $projectscategory_type_term = get_the_terms($post->ID, 'projectscategory');
- if (!empty($projectscategory_type_term))
- $post_link = str_replace('%projectscategory%', array_pop($projectscategory_type_term)->
- slug, $post_link);
- else
- $post_link = str_replace('%projectscategory%', 'uncategorized', $post_link);
- }
- return $post_link;
- }
- ?>
Add Comment
Please, Sign In to add comment