WordPress Gallery page with custom post type and custom taxonomy


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. //register Gallery post type
  3. add_action('init', 'gallery_register');
  4.  
  5. function gallery_register() {
  6.  
  7. $labels = array(
  8. 'name' => __('Gallery', 'post type general name'),
  9. 'singular_name' => __('Gallery Item', 'post type singular name'),
  10. 'add_new' => __('Add New', 'gallery item'),
  11. 'add_new_item' => __('Add New Gallery Item'),
  12. 'edit_item' => __('Edit Gallery Item'),
  13. 'new_item' => __('New Gallery Item'),
  14. 'view_item' => __('View Portfolio Item'),
  15. 'search_items' => __('Search Gallery'),
  16. 'not_found' => __('Nothing found'),
  17. 'not_found_in_trash' => __('Nothing found in Trash'),
  18. 'parent_item_colon' => ''
  19. );
  20.  
  21. $args = array(
  22. 'labels' => $labels,
  23. 'public' => true,
  24. 'publicly_queryable' => true,
  25. 'show_ui' => true,
  26. 'query_var' => true,
  27. 'rewrite' => true,
  28. 'capability_type' => 'post',
  29. 'hierarchical' => false,
  30. 'menu_position' => null,
  31. 'supports' => array('title','editor','thumbnail')
  32. );
  33.  
  34. register_post_type( 'gallery' , $args );
  35. }
  36. // Register "Site type" taxonomy (As Category)
  37. register_taxonomy("Site Type", array("gallery"),
  38. "hierarchical" => true,
  39. "label" => "Site Type",
  40. "singular_label" => "Site Type",
  41. "rewrite" => true)
  42. );
  43.  
  44. //Resgister "Color" Taxonomy (As Tags)
  45. register_taxonomy("Color", array("gallery"),
  46. "hierarchical" => false,
  47. "label" => "Color",
  48. "singular_label" => "Color",
  49. "rewrite" => true)
  50. );
  51.  
  52. //gallery post meta field for website URL or source URL
  53. add_action("admin_init", "admin_init");
  54.  
  55. function admin_init(){
  56. add_meta_box("source_url", "Source URL", "source_url", "gallery", "normal", "low");
  57. }
  58.  
  59. function source_url(){
  60. global $post;
  61. $custom = get_post_custom($post->ID);
  62. $source_url = $custom["source_url"][0];
  63. ?>
  64. <label>source URL:</label>
  65. <input name="source_url" value="<?php echo $source_url; ?>" />
  66. <?php
  67. }
  68. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.