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

Posted

tags:

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

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

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

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

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

php 带有分类的自定义帖子类型中单个项目的面包屑

Wordpress Ajax 自定义分类法

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

php 在自定义帖子类型中显示所有自定义分类中的所有帖子。