2014-01-05 79 views
2

我正在尝试获取自定义帖子类型的链接 - 视频。我已经这样做实现了这个:自定义帖子类型的固定链接

get_post_type_archive_link('video'); 

这将返回http://mylink.co.uk/video这是高明而正是我所期待的。但是,当我点击自定义帖子类型类别时,例如... LIVE并加载筛选结果时,使用get_post_type_archive_link('video');的脚本链接现在更改为显示http://mylink.co.uk/category/live/LIVE类别链接。

出了什么问题?

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); 
+0

你的意思是“现在指向现场类别”。链接是否改变了? –

+0

是的链接更改为实时类别 – user2966586

+0

所以,你的意思是现在说'get_post_type_archive_link('video');'是在分类页面上返回这个'http:// mylink.co.uk/category/live /'。对? –

回答

0

我不知道为什么会这样。我阅读了代码(包括你的和WordPress的源代码),并没有找到它的原因。我可以告诉你,只有两件事情,可能会或可能不会有帮助: -

首先

这条线: -

register_post_type('Video', $args); 

应该是这样的: -

register_post_type('video', $args); // small v 

你可以做的一个快速和肮脏的解决方法是'硬编码'视频文章类型存档链接。尝试在你的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); 

现在,每当你会打电话给此:

get_post_type_archive_link('video'); 

您将获得:

http://mylink.co.uk/video 

只适用于视频定制帖子类型。

+0

这真是一个肮脏的伎俩。使用'site_url()'使它变得至少有点动态,并将post_type'video'存储在一个变量中。 –

相关问题