【发布时间】:2012-01-01 08:49:20
【问题描述】:
我最近在 wordpress 网站中创建了几种自定义帖子类型,使用下面的代码,它们以正确的形式生成链接,例如root/category/id/postname 但每个链接都指向完整的帖子、分页或类别 404。
我尝试了许多流行的解决方案,将 /%category%/%post_id%/ 附加到 url 结构,重写函数名称,但我没有快速实现。
将 wordpress 永久链接结构设置为默认值,例如root/?page_id=1257 一切正常。
任何添加额外参数以重写(见下文)的努力都会产生“解析错误:语法错误,意外';'”,即使没有';'存在。
'rewrite' => array(
'slug' => 'issue')
任何帮助表示赞赏 - 非常困惑,非常沮丧!
<?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']);
}
?>
【问题讨论】: