获取分类标准(用于自定义帖子类型)默认使用父档案样式(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
最满意答案
事实证明我的代码工作正常,但我发送到数据库以测试函数的查询没有任何返回的行。
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 ...
-
谷歌地图中的标记(Markers in google maps)[2023-11-01]
只需初始化初始化函数外的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 ... -
Google Maps API + Google Maps Engine /我的地图(Google Maps API + Google Maps Engine / My Maps)[2023-03-15]
您也可以下载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 ...
-
标记没有显示在谷歌地图上(Markers not showing on google maps)[2021-08-07]
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 ...