自定义帖子类型固定链接不起作用

时间:2012-06-22 作者:Tim

我是否错误地声明了自定义帖子类型?

我的永久链接只在我的网站上间歇工作。

我相信我的服务器设置正确;我在Wordpress安装的同时安装了一些Drupal,它们干净的URL/htaccess规则运行良好。

我也尝试过禁用所有插件,但没有效果。

我会错过什么?

提前谢谢。

function five_oh_one_customizations_custom_post_types(){
$homepage_args = array(
    \'public\' => true,
    \'supports\' => array(
        \'title\', \'editor\', \'thumbnail\', \'custom_fields\', \'revisions\'
    ),
    \'labels\' => array(
        \'name\' => \'Homepages\',
        \'singular_name\' => \'Homepage\',
        \'add_new\' => \'Add new Homepage\',
        \'add_new_item\' => \'Add new Homepage\',
        \'edit_item\' => \'Edit Homepage\',
        \'new_item\' => \'New Homepage\',
        \'view_item\' => \'View Homepage\',
        \'not_found\' => \'No Homempages found\',
        \'not_found_in_trash\' => \'No Homepagess found in trash\'
    ),
    \'hiearchial\' => false,
    \'rewrite\' => array(
        \'with_front\' => false,
        \'slug\' => \'/\',
        \'feeds\' => false,
        \'pages\' => false
    ),
    \'has_archive\' => false,
    \'query_var\' => \'homepage\',
    \'show_in_nav_menus\' => false,
    \'menu_position\' => 2);

$grantee_args = array(
    \'public\' => true,
    \'supports\' => array(
        \'title\', \'editor\', \'thumbnail\', \'custom_fields\', \'revisions\'
    ),
    \'labels\' => array(
        \'name\' => \'Grantees\',
        \'singular_name\' => \'Grantee\',
        \'add_new\' => \'Add new Grantee\',
        \'add_new_item\' => \'Add new Grantee\',
        \'edit_item\' => \'Edit Grantee\',
        \'new_item\' => \'New Grantee\',
        \'view_item\' => \'View Grantee\',
        \'search_item\' => \'Search Grantees\',
        \'not_found\' => \'No Grantees found\',
        \'not_found_in_trash\' => \'No Grantees found in trash\'
    ),
    \'capability_type\' => \'post\',
    \'hiearchial\' => false,
    \'rewrite\' => array(
        \'slug\' => \'grantee\',
    ),
    \'has_archive\' => true,
    \'show_in_nav_menus\' => false,
    \'query_var\' => \'grantee\',
    \'menu_position\' => 3
);

$grantee_project_args = array(
    \'public\' => true,
    \'supports\' => array(
        \'title\', \'editor\', \'thumbnail\', \'custom_fields\', \'revisions\'
    ),
    \'labels\' => array(
        \'name\' => \'Grantee Projects\',
        \'singular_name\' => \'Grantee Project\',
        \'add_new\' => \'Add new Grantee Project\',
        \'add_new_item\' => \'Add new Grantee Project\',
        \'edit_item\' => \'Edit Grantee Project\',
        \'new_item\' => \'New Grantee Project\',
        \'view_item\' => \'View Grantee Project\',
        \'search_item\' => \'Search Grantee Projects\',
        \'not_found\' => \'No Grantee Projects found\',
        \'not_found_in_trash\' => \'No Grantee Projects found in trash\'
    ),
    \'capability_type\' => \'post\',
    \'hiearchial\' => false,
    \'rewrite\' => array(
        \'slug\' => \'grantee-project\'
    ),
    \'has_archive\' => true,
    \'show_in_nav_menus\' => false,
    \'query_var\' => \'grantee_project\',
    \'menu_position\' => 4
);

//create custom content types - we\'ll add the custom fields manually in the ui with the Advanced Custom Fields plugin
//http://www.advancedcustomfields.com/docs/getting-started/ 
register_post_type(\'homepage\', $homepage_args);
register_post_type(\'grantee\', $grantee_args);
register_post_type(\'grantee_project\', $grantee_project_args);

//create custom taxonomy for grantee project content type   
$taxonomy_args = array(
    \'public\' => true,
    \'show_ui\' => true,
    \'hierarchical\' => true,
    \'query_var\' => \'grantee_project_taxonomy\',
    \'rewrite\' => false,
    \'show_tagcloud\' => false,
    \'show_in_nav_menus\' => false,
    \'capabilities\' => array(
        \'manage_terms\' => \'do_not_alllow\',
        \'edit_terms\' => \'do_not_allow\',
        \'delete_terms\' => \'do_not_allow\',
        \'assign_terms\' => \'edit_posts\'
    ),
    \'labels\' => array(
        \'name\' => \'Investment Categories\',
        \'singular_name\' => \'Investment Category\',
        \'all_items\' => \'All Categories\',
        \'parent_item\' => \'Parent Category\',
    )
);

register_taxonomy(\'grantee_project_categories\', array(\'grantee_project\'), $taxonomy_args);
}

1 个回复
最合适的回答,由SO网友:Kevin 整理而成

您的重写slug设置为“/”-这将是一个问题。它必须是有效字符串。默认情况下,它将是“homepage”,这是自定义帖子类型的名称,但如果您正在寻找特定的URL结构,您可以在这里将其更改为其他内容(例如“homepages”)。

结束

相关推荐

Multiple permalinks

我的博客使用/?p=378 多年的permalink构造。这对Google Analytics没有多大帮助,我想把它改为YEAR/MONTH/DAY/post-title 结构有没有一种方法可以做到这一点而不丢失向后兼容性,以便旧的链接可以工作?