Last active
January 17, 2019 16:21
-
-
Save Rhymes2k/e4b4a8c4e06211c64dfd to your computer and use it in GitHub Desktop.
WordPress Gallery Page With Custom Post Type And Custom Taxonomy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//register Gallery post type | |
add_action('init', 'gallery_register'); | |
function gallery_register() { | |
$labels = array( | |
'name' => __('Gallery', 'post type general name'), | |
'singular_name' => __('Gallery Item', 'post type singular name'), | |
'add_new' => __('Add New', 'gallery item'), | |
'add_new_item' => __('Add New Gallery Item'), | |
'edit_item' => __('Edit Gallery Item'), | |
'new_item' => __('New Gallery Item'), | |
'view_item' => __('View Portfolio Item'), | |
'search_items' => __('Search Gallery'), | |
'not_found' => __('Nothing found'), | |
'not_found_in_trash' => __('Nothing found in Trash'), | |
'parent_item_colon' => '' | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'publicly_queryable' => true, | |
'show_ui' => true, | |
'query_var' => true, | |
'rewrite' => true, | |
'capability_type' => 'post', | |
'hierarchical' => false, | |
'menu_position' => null, | |
'supports' => array('title','editor','thumbnail') | |
); | |
register_post_type( 'gallery' , $args ); | |
} | |
// Register "Site type" taxonomy (As Category) | |
register_taxonomy("Site Type", array("gallery"), | |
array( | |
"hierarchical" => true, | |
"label" => "Site Type", | |
"singular_label" => "Site Type", | |
"rewrite" => true) | |
); | |
//Resgister "Color" Taxonomy (As Tags) | |
register_taxonomy("Color", array("gallery"), | |
array( | |
"hierarchical" => false, | |
"label" => "Color", | |
"singular_label" => "Color", | |
"rewrite" => true) | |
); | |
//gallery post meta field for website URL or source URL | |
add_action("admin_init", "admin_init"); | |
function admin_init(){ | |
add_meta_box("source_url", "Source URL", "source_url", "gallery", "normal", "low"); | |
} | |
function source_url(){ | |
global $post; | |
$custom = get_post_custom($post->ID); | |
$source_url = $custom["source_url"][0]; | |
?> | |
<label>source URL:</label> | |
<input name="source_url" value="<?php echo $source_url; ?>" /> | |
<?php | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment