Sunday, May 31, 2015

wordpress plugin for create custom category type and post type

<?php
/*
Plugin Name: MK custom texonomy and post type
Plugin URI: https://www.google.com/
Description: Admin can create its custom category and posts and view on frontend side.
Author: Mayank Patel
Version: 1.0.8
Author URI: http://www.google.com/
Text Domain: cpt-plugin
Domain Path: /languages
License: GPLv2
*/

function my_custom_post_article() {
  $args = array();
  register_post_type( 'article', $args );
}
add_action( 'init', 'my_custom_post_article' );

function my_custom_post_articles() {
  $labels = array(
    'name'               => _x( 'Articles', 'post type general name' ),
    'singular_name'      => _x( 'Article', 'post type singular name' ),
    'add_new'            => _x( 'Add New', 'book' ),
    'add_new_item'       => __( 'Add New Article' ),
    'edit_item'          => __( 'Edit Article' ),
    'new_item'           => __( 'New Article' ),
    'all_items'          => __( 'All Articles' ),
    'view_item'          => __( 'View Article' ),
    'search_items'       => __( 'Search Articles' ),
    'not_found'          => __( 'No article found' ),
    'not_found_in_trash' => __( 'No article found in the Trash' ),
    'parent_item_colon'  => '',
    'menu_name'          => 'Article'
  );
  $args = array(
    'labels'        => $labels,
    'description'   => 'Holds our article and article specific data',
    'public'        => true,
    'menu_position' => 5,
   'supports'      => array( 'title','author', 'editor','thumbnail','trackbacks' ,'excerpt','comments' ,'custom-fields','revisions','page-attributes','post-formats'),
    'has_archive'   => true,
  );
  register_post_type( 'article', $args );
}
add_action( 'init', 'my_custom_post_articles' );


function my_updated_messages( $messages )
{
  global $post, $post_ID;
  $messages['article'] = array(
    0 => '',
    1 => sprintf( __('Article updated. <a href="%s">View article</a>'), esc_url( get_permalink($post_ID) ) ),
    2 => __('Custom field updated.'),
    3 => __('Custom field deleted.'),
    4 => __('Article updated.'),
    5 => isset($_GET['revision']) ? sprintf( __('Article restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
    6 => sprintf( __('Article published. <a href="%s">View article</a>'), esc_url( get_permalink($post_ID) ) ),
    7 => __('Article saved.'),
    8 => sprintf( __('Article submitted. <a target="_blank" href="%s">Preview article</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
    9 => sprintf( __('Article scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview article</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    10 => sprintf( __('Article draft updated. <a target="_blank" href="%s">Preview article</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
  );
  return $messages;
}
add_filter( 'post_updated_messages', 'my_updated_messages' );

function my_taxonomies_article()
{
 // Hirarchical false = tags and true = categories
 register_taxonomy("article_category", array("article"), array("hierarchical" => true, "label" => "Categories", "singular_label" => "Article", "rewrite" => true));
 register_taxonomy("article_tags", array("article"), array("hierarchical" => false, "label" => "Tags", "singular_label" => "tags", "rewrite" => true));
}

add_action( 'init', 'my_taxonomies_article',0);

No comments:

Post a Comment

Please mention your comments.......