Wordpress 自定义帖子类型的永久链接
我正在尝试获取一个自定义帖子类型-视频的链接。我通过以下行动实现了这一目标:Wordpress 自定义帖子类型的永久链接,wordpress,categories,Wordpress,Categories,我正在尝试获取一个自定义帖子类型-视频的链接。我通过以下行动实现了这一目标: get_post_type_archive_link( 'video' ); 这是辉煌的回报,这正是我所寻找的。但是,当我点击一个自定义的帖子类型类别,例如…LIVE并加载过滤结果时,脚本链接使用get_post_type_archive_链接('video')现在更改为显示http://mylink.co.uk/category/live/ 怎么了 更新 function custom_post_type_vide
get_post_type_archive_link( 'video' );
这是辉煌的回报,这正是我所寻找的。但是,当我点击一个自定义的帖子类型类别,例如…LIVE
并加载过滤结果时,脚本链接使用get_post_type_archive_链接('video')代码>现在更改为显示http://mylink.co.uk/category/live/
怎么了
更新
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 );
我不知道为什么会这样。我读了代码(你的和WordPress的源代码),但没有发现为什么会这样。我只能告诉你两件可能有用也可能没用的事:-
弗斯特
这一行:-
register_post_type( 'Video', $args );
应该是这样的:-
register_post_type( 'video', $args ); // small v
第二
您可以做的一个快速而肮脏的解决方法是“硬编码”video post类型的归档链接。尝试在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);
您将获得:
http://mylink.co.uk/video
仅适用于视频自定义帖子类型。您所说的“现在指向LIVE类别”是什么意思?链接变了吗?是的,链接变为LIVE类别所以,你的意思是现在get_post_type_archive_link('video')代码>正在返回此http://mylink.co.uk/category/live/
在类别页面上。对吗?@OmarTariq这是正确的。你能粘贴你注册post type视频的代码吗?我的意思是说这个函数的代码register\u post\u type
。还有争论。对于这个问题,我有一个下流的技巧。但我只想知道几件事。这真是个卑鄙的把戏。使用site\u url()
使其至少有一点动态,并将post\u typevideo
存储在变量中。
http://mylink.co.uk/video