Wordpress 自定义帖子类型帖子和类别链接 404 [英] Wordpress custom post type post and category links 404
问题描述
我最近在 wordpress 站点中创建了几种自定义帖子类型,使用下面的代码,它们以正确的形式生成链接,例如root/category/id/postname 但每个链接都指向完整的帖子、分页或类别 404.
我尝试了许多流行的解决方案,将/%category%/%post_id%/附加到 url 结构,重写函数名称,但我无处可去.
将 wordpress 永久链接结构设置为默认值,例如root/?page_id=1257 一切正常.
任何添加额外参数以重写(见下文)的努力都会产生解析错误:语法错误,意外的 ';'",即使没有 ';'存在.
'rewrite' =>大批('slug' =>'问题')
感谢任何帮助 - 非常困惑,非常沮丧!
__('按'),'singular_label' =>__('按'),'公共' =>真的,'show_ui' =>真的,'capability_type' =>'邮政','new_item' =>__('新新闻项目'),'分层' =>错误的,'重写' =>真的,'支持' =>array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'comments', 'revisions', 'page-attributes', 'post-formats'));register_taxonomy('press-category', array('article'),大批('标签' =>'新闻报道类别','singular_label' =>'新闻报道类','公共' =>真的,'show_tagcloud' =>真的,'分层' =>真的,'query_var' =>真的,'menu_position' =>5、'重写' =>真的));register_post_type('mjwpress', $args);}add_action('inthenews_init', 'inthenews_init');add_action('save_post', 'save_mjwpress_options');函数 inthenews_init(){add_meta_box('newsmeta', 'Press Options', 'mjwpress_meta_options', 'mjwpress', 'normal', 'low');}函数 mjwpress_meta_options(){全球 $post;$custom = get_post_custom($post->ID);$linkurl = $custom['linkurl'][0];$linktitle = $custom['linktitle'][0];?><label for='linkurl'>链接到外部出版物:</label><input name='linkurl' value='<?php echo $linkurl;?>'/><p>例如http://www.example.com/article-title.php</p><label for='linktitle'>外部出版物的标题:</label><input name='linktitle' value='<?php echo $linktitle;?>'/><p>例如自由民主党之声</p><?php}函数 save_mjwpress_options(){全球 $post;update_post_meta($post->ID, 'linkurl', $_POST['linkurl']);update_post_meta($post->ID, 'linktitle', $_POST['linktitle']);}?>
事实证明,分类法和帖子类型出现的顺序在重写方面很重要.
请参阅 http://mondaybynoon.com/2011/05/20/revisiting-custom-post-types-taxonomies-permalinks-slugs/
'品牌','singular_name' =>'牌','search_items' =>'搜索品牌','popular_items' =>'流行品牌','all_items' =>'所有品牌','parent_item' =>'母品牌','edit_item' =>'编辑品牌','update_item' =>'更新品牌','add_new_item' =>'添加新品牌','new_item_name' =>'新品牌','separate_items_with_commas' =>'用逗号分隔品牌','add_or_remove_items' =>'添加或删除品牌','choose_from_most_used' =>'从最常用的品牌中选择');$args = 数组('标签' =>'品牌','标签' =>$标签,'公共' =>真的,'分层' =>真的,'show_ui' =>真的,'show_in_nav_menus' =>真的,'参数' =>数组('orderby' => 'term_order'),'重写' =>数组('slug' => 'cameras/brands', 'with_front' => false ),'query_var' =>真的);register_taxonomy('品牌','相机',$args);//帖子类型,必须在分类之后...register_post_type('相机',大批('标签' =>大批('名称' =>__( '相机' ),'singular_name' =>__( '相机' )),'公共' =>真的,'show_ui' =>真的,'show_in_menu' =>真的,'支持' =>数组('标题','编辑','缩略图'),'重写' =>数组('slug' => 'cameras', 'with_front' => false ),'has_archive' =>真的));?>
I've recently created several custom post types in a wordpress site, with the code below, they are generating links in the correct form e.g. root/category/id/postname but each link to the full post, pagination or category 404's.
I've tried a number of popular solutions, appending /%category%/%post_id%/ to the url structure, rewriting function names but I'm getting nowhere fast.
With the wordpress permalink structure set to default e.g. root/?page_id=1257 everything works ok.
Any effort to add additional parameters to rewrite (see below) produces "Parse error: syntax error, unexpected ';'" even though no ';' is present.
'rewrite' => array(
'slug' => 'issue')
Any help appreciated - highly confused, very frustrated!
<?php
// CUSTOM POST TYPE 1
add_action('init', 'mjwpress_register');
function mjwpress_register() {
$args = array(
'label' => __('Press'),
'singular_label' => __('Press'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'new_item' => __('New Press Item'),
'hierarchical' => false,
'rewrite' => true,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'comments', 'revisions', 'page-attributes', 'post-formats')
);
register_taxonomy('press-category', array('article'),
array(
'label' => 'Press Story Category',
'singular_label' => 'press-story-category',
'public' => TRUE,
'show_tagcloud' => TRUE,
'hierarchical' => TRUE,
'query_var' => TRUE,
'menu_position' => 5,
'rewrite' => TRUE)
);
register_post_type( 'mjwpress' , $args );
}
add_action('inthenews_init', 'inthenews_init');
add_action('save_post', 'save_mjwpress_options');
function inthenews_init(){
add_meta_box('newsmeta', 'Press Options', 'mjwpress_meta_options', 'mjwpress', 'normal', 'low');
}
function mjwpress_meta_options(){
global $post;
$custom = get_post_custom($post->ID);
$linkurl = $custom['linkurl'][0];
$linktitle = $custom['linktitle'][0];
?>
<div class='form-wrap'>
<div class='form-field'>
<label for='linkurl'>Link to External Publication:</label>
<input name='linkurl' value='<?php echo $linkurl; ?>' />
<p>E.g. http://www.example.com/article-title.php</p>
</div>
<div class='form-field'>
<label for='linktitle'>Title of External Publication:</label>
<input name='linktitle' value='<?php echo $linktitle; ?>' />
<p>E.g. Lib Dem Voice</p>
</div>
</div>
<?php
}
function save_mjwpress_options(){
global $post;
update_post_meta($post->ID, 'linkurl', $_POST['linkurl']);
update_post_meta($post->ID, 'linktitle', $_POST['linktitle']);
}
?>
It turns out the the order taxonomy and post type occur in is important where rewrite is concerned.
See http://mondaybynoon.com/2011/05/20/revisiting-custom-post-types-taxonomies-permalinks-slugs/
<?php
// Links post type...
// Taxonomy
$labels = array(
'name' => 'Brands',
'singular_name' => 'Brand',
'search_items' => 'Search Brands',
'popular_items' => 'Popular Brands',
'all_items' => 'All Brands',
'parent_item' => 'Parent Brand',
'edit_item' => 'Edit Brand',
'update_item' => 'Update Brand',
'add_new_item' => 'Add New Brand',
'new_item_name' => 'New Brand',
'separate_items_with_commas' => 'Separate Brands with commas',
'add_or_remove_items' => 'Add or remove Brands',
'choose_from_most_used' => 'Choose from most used Brands'
);
$args = array(
'label' => 'Brands',
'labels' => $labels,
'public' => true,
'hierarchical' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array( 'slug' => 'cameras/brands', 'with_front' => false ),
'query_var' => true
);
register_taxonomy( 'brands', 'cameras', $args );
//Post type, must come after the taxonomy...
register_post_type( 'cameras',
array(
'labels' => array(
'name' => __( 'Cameras' ),
'singular_name' => __( 'Camera' )
),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
'rewrite' => array( 'slug' => 'cameras', 'with_front' => false ),
'has_archive' => true
)
);
?>
这篇关于Wordpress 自定义帖子类型帖子和类别链接 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!