首页 \ 问答 \ 获取分类标准(用于自定义帖子类型)默认使用父档案样式(Get taxonomies (for custom post type) to use parent archive styling by default)

获取分类标准(用于自定义帖子类型)默认使用父档案样式(Get taxonomies (for custom post type) to use parent archive styling by default)

我刚刚创建了一个名为research的新自定义帖子类型。 我添加了三个分类法,研究领域,作者和出版物。 然后我创建了archive-research.php和content-research.php来创建不同的风格。 我的印象是所有来自研究的分类法都会使用这个档案,所以我错了或者搞砸了。 各种分类标准的要点是能够创建各种我可以添加到菜单中的列表,但它们最终都会使用默认归档。 使用自定义存档的唯一方法是访问mywebsite.com/research,但显示所有内容。 我知道也可以创建自定义分类法模板,但是默认情况下是否有一些方法让分类法使用其父档案?

无论如何,这里是我目前使用的代码,也许我只是错过了一些东西,我还是比较新的WordPress。

function create_research_cpt() {

$labels = array(
    'name' => __( 'Research', 'Post Type General Name', 'textdomain' ),
    'singular_name' => __( 'Research', 'Post Type Singular Name', 'textdomain' ),
    'menu_name' => __( 'Research', 'textdomain' ),
    'name_admin_bar' => __( 'Research', 'textdomain' ),
    'archives' => __( 'Research Archives', 'textdomain' ),
    'attributes' => __( 'Research Attributes', 'textdomain' ),
    'parent_item_colon' => __( 'Parent Research:', 'textdomain' ),
    'all_items' => __( 'All Research', 'textdomain' ),
    'add_new_item' => __( 'Add New Research', 'textdomain' ),
    'add_new' => __( 'Add New', 'textdomain' ),
    'new_item' => __( 'New Research', 'textdomain' ),
    'edit_item' => __( 'Edit Research', 'textdomain' ),
    'update_item' => __( 'Update Research', 'textdomain' ),
    'view_item' => __( 'View Research', 'textdomain' ),
    'view_items' => __( 'View Research', 'textdomain' ),
    'search_items' => __( 'Search Research', 'textdomain' ),
    'not_found' => __( 'Not found', 'textdomain' ),
    'not_found_in_trash' => __( 'Not found in Trash', 'textdomain' ),
    'featured_image' => __( 'Featured Image', 'textdomain' ),
    'set_featured_image' => __( 'Set featured image', 'textdomain' ),
    'remove_featured_image' => __( 'Remove featured image', 'textdomain' ),
    'use_featured_image' => __( 'Use as featured image', 'textdomain' ),
    'insert_into_item' => __( 'Insert into Research', 'textdomain' ),
    'uploaded_to_this_item' => __( 'Uploaded to this Research', 'textdomain' ),
    'items_list' => __( 'Research list', 'textdomain' ),
    'items_list_navigation' => __( 'Research list navigation', 'textdomain' ),
    'filter_items_list' => __( 'Filter Research list', 'textdomain' ),
);
$args = array(
    'label' => __( 'Research', 'textdomain' ),
    'description' => __( 'Studies, Papers, Data & Research', 'textdomain' ),
    'labels' => $labels,
    'menu_icon' => 'dashicons-admin-page',
    'supports' => array('title', 'editor', 'thumbnail', ),
    'taxonomies' => array('field', 'authors', 'publications', ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'menu_position' => 5,
    'show_in_admin_bar' => true,
    'show_in_nav_menus' => true,
    'can_export' => true,
    'has_archive' => true,
    'hierarchical' => true,
    'exclude_from_search' => false,
    'show_in_rest' => true,
    'publicly_queryable' => true,
    'capability_type' => 'post',
);
register_post_type( 'research', $args );

}
add_action( 'init', 'create_research_cpt', 0 );

function create_field_tax() {

$labels = array(
    'name'              => _x( 'Research Fields', 'taxonomy general name', 'textdomain' ),
    'singular_name'     => _x( 'Research Field', 'taxonomy singular name', 'textdomain' ),
    'search_items'      => __( 'Search Research Fields', 'textdomain' ),
    'all_items'         => __( 'All Research Fields', 'textdomain' ),
    'parent_item'       => __( 'Parent Research Field', 'textdomain' ),
    'parent_item_colon' => __( 'Parent Research Field:', 'textdomain' ),
    'edit_item'         => __( 'Edit Research Field', 'textdomain' ),
    'update_item'       => __( 'Update Research Field', 'textdomain' ),
    'add_new_item'      => __( 'Add New Research Field', 'textdomain' ),
    'new_item_name'     => __( 'New Research Field Name', 'textdomain' ),
    'menu_name'         => __( 'Research Field', 'textdomain' ),
);
$args = array(
    'labels' => $labels,
    'description' => __( '', 'textdomain' ),
    'hierarchical' => true,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'show_in_rest' => false,
    'show_tagcloud' => true,
    'show_in_quick_edit' => true,
    'show_admin_column' => false,
);
register_taxonomy( 'field', array('research', ), $args );

}
add_action( 'init', 'create_field_tax' );


function create_author_tax() {

$labels = array(
    'name'              => _x( 'Authors', 'taxonomy general name', 'textdomain' ),
    'singular_name'     => _x( 'Author', 'taxonomy singular name', 'textdomain' ),
    'search_items'      => __( 'Search Authors', 'textdomain' ),
    'all_items'         => __( 'All Authors', 'textdomain' ),
    'parent_item'       => __( 'Parent Author', 'textdomain' ),
    'parent_item_colon' => __( 'Parent Author:', 'textdomain' ),
    'edit_item'         => __( 'Edit Author', 'textdomain' ),
    'update_item'       => __( 'Update Author', 'textdomain' ),
    'add_new_item'      => __( 'Add New Author', 'textdomain' ),
    'new_item_name'     => __( 'New Author Name', 'textdomain' ),
    'menu_name'         => __( 'Author', 'textdomain' ),
);
$args = array(
    'labels' => $labels,
    'description' => __( '', 'textdomain' ),
    'hierarchical' => false,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'show_in_rest' => false,
    'show_tagcloud' => true,
    'show_in_quick_edit' => true,
    'show_admin_column' => false,
);
register_taxonomy( 'author', array('research', ), $args );

}
add_action( 'init', 'create_author_tax' );



function create_publication_tax() {

$labels = array(
    'name'              => _x( 'Publications', 'taxonomy general name', 'textdomain' ),
    'singular_name'     => _x( 'Publication', 'taxonomy singular name', 'textdomain' ),
    'search_items'      => __( 'Search Publications', 'textdomain' ),
    'all_items'         => __( 'All Publications', 'textdomain' ),
    'parent_item'       => __( 'Parent Publication', 'textdomain' ),
    'parent_item_colon' => __( 'Parent Publication:', 'textdomain' ),
    'edit_item'         => __( 'Edit Publication', 'textdomain' ),
    'update_item'       => __( 'Update Publication', 'textdomain' ),
    'add_new_item'      => __( 'Add New Publication', 'textdomain' ),
    'new_item_name'     => __( 'New Publication Name', 'textdomain' ),
    'menu_name'         => __( 'Publication', 'textdomain' ),
);
$args = array(
    'labels' => $labels,
    'description' => __( '', 'textdomain' ),
    'hierarchical' => false,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'show_in_rest' => false,
    'show_tagcloud' => true,
    'show_in_quick_edit' => true,
    'show_admin_column' => false,
);
register_taxonomy( 'publication', array('research', ), $args );

}
add_action( 'init', 'create_publication_tax' );

I just created a new custom post type called research. I added three taxonomies, research field, author and publication. I then created archive-research.php and content-research.php to create a different style. I was under the impression that all the taxonomies from research would use this archive, so I was either wrong or I've screwed something up. The whole point of the various taxonomies was to be able to create various listings I could add to the menu, but they all end up using the default archive. The only way to use the custom archive is to visit mywebsite.com/research, but that shows everything. I know it's possible to create custom taxonomies templates as well, but is there is some way to have the taxonomies use their parent archive by default?

Anyway, here is the code I'm currently using, maybe I'm just missing something, I'm still rather new at wordpress.

function create_research_cpt() {

$labels = array(
    'name' => __( 'Research', 'Post Type General Name', 'textdomain' ),
    'singular_name' => __( 'Research', 'Post Type Singular Name', 'textdomain' ),
    'menu_name' => __( 'Research', 'textdomain' ),
    'name_admin_bar' => __( 'Research', 'textdomain' ),
    'archives' => __( 'Research Archives', 'textdomain' ),
    'attributes' => __( 'Research Attributes', 'textdomain' ),
    'parent_item_colon' => __( 'Parent Research:', 'textdomain' ),
    'all_items' => __( 'All Research', 'textdomain' ),
    'add_new_item' => __( 'Add New Research', 'textdomain' ),
    'add_new' => __( 'Add New', 'textdomain' ),
    'new_item' => __( 'New Research', 'textdomain' ),
    'edit_item' => __( 'Edit Research', 'textdomain' ),
    'update_item' => __( 'Update Research', 'textdomain' ),
    'view_item' => __( 'View Research', 'textdomain' ),
    'view_items' => __( 'View Research', 'textdomain' ),
    'search_items' => __( 'Search Research', 'textdomain' ),
    'not_found' => __( 'Not found', 'textdomain' ),
    'not_found_in_trash' => __( 'Not found in Trash', 'textdomain' ),
    'featured_image' => __( 'Featured Image', 'textdomain' ),
    'set_featured_image' => __( 'Set featured image', 'textdomain' ),
    'remove_featured_image' => __( 'Remove featured image', 'textdomain' ),
    'use_featured_image' => __( 'Use as featured image', 'textdomain' ),
    'insert_into_item' => __( 'Insert into Research', 'textdomain' ),
    'uploaded_to_this_item' => __( 'Uploaded to this Research', 'textdomain' ),
    'items_list' => __( 'Research list', 'textdomain' ),
    'items_list_navigation' => __( 'Research list navigation', 'textdomain' ),
    'filter_items_list' => __( 'Filter Research list', 'textdomain' ),
);
$args = array(
    'label' => __( 'Research', 'textdomain' ),
    'description' => __( 'Studies, Papers, Data & Research', 'textdomain' ),
    'labels' => $labels,
    'menu_icon' => 'dashicons-admin-page',
    'supports' => array('title', 'editor', 'thumbnail', ),
    'taxonomies' => array('field', 'authors', 'publications', ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'menu_position' => 5,
    'show_in_admin_bar' => true,
    'show_in_nav_menus' => true,
    'can_export' => true,
    'has_archive' => true,
    'hierarchical' => true,
    'exclude_from_search' => false,
    'show_in_rest' => true,
    'publicly_queryable' => true,
    'capability_type' => 'post',
);
register_post_type( 'research', $args );

}
add_action( 'init', 'create_research_cpt', 0 );

function create_field_tax() {

$labels = array(
    'name'              => _x( 'Research Fields', 'taxonomy general name', 'textdomain' ),
    'singular_name'     => _x( 'Research Field', 'taxonomy singular name', 'textdomain' ),
    'search_items'      => __( 'Search Research Fields', 'textdomain' ),
    'all_items'         => __( 'All Research Fields', 'textdomain' ),
    'parent_item'       => __( 'Parent Research Field', 'textdomain' ),
    'parent_item_colon' => __( 'Parent Research Field:', 'textdomain' ),
    'edit_item'         => __( 'Edit Research Field', 'textdomain' ),
    'update_item'       => __( 'Update Research Field', 'textdomain' ),
    'add_new_item'      => __( 'Add New Research Field', 'textdomain' ),
    'new_item_name'     => __( 'New Research Field Name', 'textdomain' ),
    'menu_name'         => __( 'Research Field', 'textdomain' ),
);
$args = array(
    'labels' => $labels,
    'description' => __( '', 'textdomain' ),
    'hierarchical' => true,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'show_in_rest' => false,
    'show_tagcloud' => true,
    'show_in_quick_edit' => true,
    'show_admin_column' => false,
);
register_taxonomy( 'field', array('research', ), $args );

}
add_action( 'init', 'create_field_tax' );


function create_author_tax() {

$labels = array(
    'name'              => _x( 'Authors', 'taxonomy general name', 'textdomain' ),
    'singular_name'     => _x( 'Author', 'taxonomy singular name', 'textdomain' ),
    'search_items'      => __( 'Search Authors', 'textdomain' ),
    'all_items'         => __( 'All Authors', 'textdomain' ),
    'parent_item'       => __( 'Parent Author', 'textdomain' ),
    'parent_item_colon' => __( 'Parent Author:', 'textdomain' ),
    'edit_item'         => __( 'Edit Author', 'textdomain' ),
    'update_item'       => __( 'Update Author', 'textdomain' ),
    'add_new_item'      => __( 'Add New Author', 'textdomain' ),
    'new_item_name'     => __( 'New Author Name', 'textdomain' ),
    'menu_name'         => __( 'Author', 'textdomain' ),
);
$args = array(
    'labels' => $labels,
    'description' => __( '', 'textdomain' ),
    'hierarchical' => false,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'show_in_rest' => false,
    'show_tagcloud' => true,
    'show_in_quick_edit' => true,
    'show_admin_column' => false,
);
register_taxonomy( 'author', array('research', ), $args );

}
add_action( 'init', 'create_author_tax' );



function create_publication_tax() {

$labels = array(
    'name'              => _x( 'Publications', 'taxonomy general name', 'textdomain' ),
    'singular_name'     => _x( 'Publication', 'taxonomy singular name', 'textdomain' ),
    'search_items'      => __( 'Search Publications', 'textdomain' ),
    'all_items'         => __( 'All Publications', 'textdomain' ),
    'parent_item'       => __( 'Parent Publication', 'textdomain' ),
    'parent_item_colon' => __( 'Parent Publication:', 'textdomain' ),
    'edit_item'         => __( 'Edit Publication', 'textdomain' ),
    'update_item'       => __( 'Update Publication', 'textdomain' ),
    'add_new_item'      => __( 'Add New Publication', 'textdomain' ),
    'new_item_name'     => __( 'New Publication Name', 'textdomain' ),
    'menu_name'         => __( 'Publication', 'textdomain' ),
);
$args = array(
    'labels' => $labels,
    'description' => __( '', 'textdomain' ),
    'hierarchical' => false,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'show_in_rest' => false,
    'show_tagcloud' => true,
    'show_in_quick_edit' => true,
    'show_admin_column' => false,
);
register_taxonomy( 'publication', array('research', ), $args );

}
add_action( 'init', 'create_publication_tax' );

原文:https://stackoverflow.com/questions/48914790
更新时间:2022-04-13 06:04

最满意答案

事实证明我的代码工作正常,但我发送到数据库以测试函数的查询没有任何返回的行。


It turns out my code was working ok, but that the query I was sending to the database to test the function didn't have any returned rows.

相关问答

更多
  • 这不可能。 ui-gmap专门针对纬度和经度。 This is not possible. The ui-gmap looks specifically for latitude and longitude.
  • 经过一些挖掘,我找到了一个非常好的网站,有很多自定义图标,你甚至可以用自己的颜色,字母等设计自己的网站。 http://mapicons.nicolasmollet.com/ Well after some more digging I found a really nice site that has a lot of custom icons and where you can even design your own with your own colors, letters etc. http:// ...
  • 您必须将Map-instance存储在initialize内部可访问的位置,然后您将能够在进一步调用时重新使用Map,并且只能删除以前的标记并绘制新标记。 Sample(将Map存储为map-div的属性): function initialize(markers) { var node = document.getElementById('map-canvas'), j = 0, marker; //create a single Map-instanc ...
  • 事实证明我的代码工作正常,但我发送到数据库以测试函数的查询没有任何返回的行。 It turns out my code was working ok, but that the query I was sending to the database to test the function didn't have any returned rows.
  • 我想你一次只能显示一个信息窗口。 另一种方法是使用自定义标记,它包含标记和信息窗口(您需要将自己渲染到标记图像中)。 I think you can only display one info window at a time. An alternative might be to use custom markers, which contain both the marker and the info window (which you'd need to render yourself into th ...
  • 只需初始化初始化函数外的map变量即可: google.load("maps", "2.x"); var map; // Call this function when the page has been loaded function initialize() { map = new google.maps.Map2(document.getElementById("map")); map.setCenter(new google.maps.LatLng(52,-3), 13); va ...
  • 您也可以下载KML等地图,下载网址类似 https://www.google.com/maps/d/kml?mid=themymaps.mapid 它没有记录,但是当我使用这个URL创建一个KmlLayer的时候它现在对我很有用(只要它们没有修改下载过程,它就会工作)。 示例( 原始地图 ) function initialize() { var map = new google.maps.Map(document.getElementById('map-canvas'), { zo ...
  • 从版本1.3.1开始,这是不可能的。 这已经在TODO列表中,因此您可能希望将问题10标记为通知进度。 编辑: 这可以通过简单的调用从版本1.5开始提供: theMarker.setClusterGroup(777); 默认组为0 ,只有具有相同组的Marker聚集在一起,因此如果为每个Marker类型分配一些int值,那么你就会很好。 This is not possible as of version 1.3.1 of the library. This is already on the TODO ...
  • 请注意我没有测试过这个,因为我没有带xml的数据库方便 首先,您需要将load()函数拆分为一个函数,该函数初始化地图并在domready上加载标记,以及稍后将用于处理xml并使用更新地图的函数。 这需要完成,因此您不必在每次加载时重新初始化地图。 其次,您需要决定如何处理已在地图上绘制的标记。 为此,您需要在将它们添加到地图时将它们添加到数组中。 在第二次更新时,您可以选择重绘标记(重建阵列)或只更新现有阵列。 我的示例显示了您只需从屏幕清除旧标记的情况(这更简单)。 //global array to ...
  • map是一个局部变量,只在initialize可见。 设置标记的map -property时,请使用this代替map : function addMarker(event) { markers.push(event.latLng); marker = new google.maps.Marker({ position: event.latLng, map: this }); } 说明: 回调将在触发事件的对象范围内执行。 这是Maps-insta ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)