[英]Permalink of a custom post type
I am trying to get the link to a custom post type - Video. 我正在尝试链接到自定义帖子类型-视频。 I have achieved this by doing: 我已经做到了:
get_post_type_archive_link( 'video' );
This returns http://mylink.co.uk/video which is brillant and exactly what I am looking for. 这将返回http://mylink.co.uk/video ,该视频非常好,而且正是我要的内容。 However, when I click onto a custom post type category for example... LIVE
and it loads the filtered results, the script link using get_post_type_archive_link( 'video' );
但是,当我单击一个自定义帖子类型类别时,例如... LIVE
,它会加载过滤的结果,脚本链接使用get_post_type_archive_link( 'video' );
now changes to the LIVE
category link showing http://mylink.co.uk/category/live/
. 现在更改为LIVE
类别链接,显示http://mylink.co.uk/category/live/
。
What is wrong? 怎么了?
UPDATE UPDATE
function custom_post_type_video() {
$labels = array(
'name' => _x( 'Videos', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Video', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Video', 'text_domain' ),
'parent_item_colon' => __( 'Parent Video:', 'text_domain' ),
'all_items' => __( 'All Video', 'text_domain' ),
'view_item' => __( 'View Video', 'text_domain' ),
'add_new_item' => __( 'Add New Video', 'text_domain' ),
'add_new' => __( 'New Video', 'text_domain' ),
'edit_item' => __( 'Edit Video', 'text_domain' ),
'update_item' => __( 'Update Video', 'text_domain' ),
'search_items' => __( 'Search Videos', 'text_domain' ),
'not_found' => __( 'No Videos found', 'text_domain' ),
'not_found_in_trash' => __( 'No Videos found in Trash', 'text_domain' ),
);
$args = array(
'label' => __( 'Video', 'text_domain' ),
'description' => __( 'Video information pages', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'revisions', ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => '',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'Video', $args );
add_action( 'init', 'my_taxonomies_product', 0 );
// Initialize Taxonomy Labels
$labels = array(
'name' => _x( 'Categories', 'taxonomy general name', 'text_domain' ),
'singular_name' => _x( 'Category', 'taxonomy singular name', 'text_domain' ),
'search_items' => __( 'Search Types', 'text_domain' ),
'all_items' => __( 'All Categories', 'text_domain' ),
'parent_item' => __( 'Parent Category', 'text_domain' ),
'parent_item_colon' => __( 'Parent Category:', 'text_domain' ),
'edit_item' => __( 'Edit Categories', 'text_domain' ),
'update_item' => __( 'Update Category', 'text_domain' ),
'add_new_item' => __( 'Add New Category', 'text_domain' ),
'new_item_name' => __( 'New Category', 'text_domain' ),
);
// Register Custom Taxonomy
register_taxonomy('tagvideo',array('video'), array(
'hierarchical' => true, // define whether to use a system like tags or categories
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'cat-video' ),
));
}
// Hook into the 'init' action
add_action( 'init', 'custom_post_type_video', 0 );
I don't know why is it so. 我不知道为什么会这样。 I read the code (both yours and WordPress' source code) and didn't find why is it so. 我阅读了代码(都是您的代码和WordPress的源代码),却没有找到原因。 I can tell you only two things that might or might not be helpful:- 我只能告诉您可能有用或可能无效的两件事:-
This line:- 这行:
register_post_type( 'Video', $args );
should be like this:- 应该是这样的:
register_post_type( 'video', $args ); // small v
One quick and dirty workaround that you can do is to 'hard-code' the video post type archive link. 您可以执行的一种快速而肮脏的解决方法是“硬编码”视频帖子类型存档链接。 Try inserting this code in your functions.php:- 尝试在您的functions.php中插入此代码:-
function video_post_type_archive_link( $link, $post_type ) {
if( $post_type === 'video' ) {
$link = 'http://mylink.co.uk/video' // <-- this should be link to 'video' post type archives
}
return $link;
}
add_filter('post_type_archive_link', 'video_post_type_archive_link', 10, 2);
Now, whenever you'll call this: 现在,只要您调用它:
get_post_type_archive_link( 'video' );
You'll get: 你会得到:
http://mylink.co.uk/video
Only for video custom post type. 仅适用于视频自定义帖子类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.