具有自定义文章类型和自定义分类的WordPress库页面

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了具有自定义文章类型和自定义分类的WordPress库页面相关的知识,希望对你有一定的参考价值。

  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. ?>

以上是关于具有自定义文章类型和自定义分类的WordPress库页面的主要内容,如果未能解决你的问题,请参考以下文章

PHP 带有自定义帖子类型和自定义分类的WordPress图库页面

Wordpress注册自定义Post类型和自定义分类法

在WordPress中显示具有自定义摘录长度和自定义阅读更多文本的文章

未找到具有自定义分页 404 的自定义分类和自定义帖子类型

如何为自定义帖子和分类法制作 Wordpress 存档页面?

Gatsby:在自定义帖子类型上使用 GraphQL 查询和自定义分类