当我们将permalink设置为Post name
然后转到wordpress的任何默认帖子,如“Testing 123”单页,其链接如下所示
localhost/foo_articles/testing-123
现在,当我们将永久链接更改为
Custom Structure
并设置如下值
%category%/%postname%
, 链接如下所示
http://localhost/foo_articles/testing/testing-123/
测试是我的类别slug
Now the main part of my question is
我制作一个插件,在其中创建一个帖子类型
foo_articles
和自定义分类法
foo_categories
它工作得很好。当我单击一个类别时,其链接如下所示
http://localhost/foo_articles/foo_category/junk-food/
当我点击一篇文章的单个页面时,它的链接如下所示
http://localhost/foo_articles/foo_articles/how-to-reduce-the-intake-of-junk-food-in-children/
foo\\u articles是我的帖子类型,可以更改
现在我的问题是,当用户设置永久链接时,如何设置链接Custom Structure
并设置如下值%category%/%postname%
我的链接也会像上面的默认贴子单页一样更改。
http://localhost/foo_articles/article cat slug/how-to-reduce-the-intake-of-junk-food-in-children/
以下是自定义邮件类型代码:
add_action(\'init\', \'foo_articles\');
function foo_articles() {
$foo_slug = \'foo_articles\';
$foo_slug = get_option(\'foo_plugin_slug\');
$labels = array(
\'name\' => __(\'Foo\', \'fff\'),
\'singular_name\' => __(\'Foo\', \'fff\'),
\'all_items\' => __(\'Articles\', \'fff\'),
\'add_new\' => __(\'New Article\', \'fff\'),
\'add_new_item\' => __(\'Add New Article\', \'fff\'),
\'edit_item\' => __(\'Edit Article\', \'fff\'),
\'new_item\' => __(\'New Article\', \'fff\'),
\'view_item\' => __(\'View Articles\', \'fff\'),
\'search_items\' => __(\'Search Articles\', \'fff\'),
\'not_found\' => __(\'Nothing found\', \'fff\'),
\'not_found_in_trash\' => __(\'Nothing found in Trash\', \'fff\'),
\'parent_item_colon\' => \'\'
);
$foo_rewrite = array(
\'slug\' => FOO_PLUGIN_SLUG, // i define this in plugin index file
\'with_front\' => true,
\'pages\' => false,
\'feeds\' => true,
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'menu_icon\' => plugin directory.\'images/icon-foo.png\',
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => 3,
\'supports\' => array(\'title\',\'editor\',\'thumbnail\',\'comments\',\'tags\'),
\'rewrite\' => $foo_rewrite,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => true
);
register_post_type( \'foo_articles\' , $args );
flush_rewrite_rules();
}
add_action( \'init\', \'foo_taxonomies\', 0 );
// Article taxonamy
function foo_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
\'name\' => __( \'Article Category\', \'fff\'),
\'singular_name\' => __( \'Article Category\', \'fff\' ),
\'search_items\' => __( \'Search Article Category\', \'fff\' ),
\'all_items\' => __( \'All Article Categories\', \'fff\' ),
\'parent_item\' => __( \'Parent Article Category\', \'fff\' ),
\'parent_item_colon\' => __( \'Parent Article Category:\', \'fff\' ),
\'edit_item\' => __( \'Edit Article Category\', \'fff\' ),
\'update_item\' => __( \'Update Article Category\', \'fff\' ),
\'add_new_item\' => __( \'Add New Article Category\', \'fff\' ),
\'new_item_name\' => __( \'New Article Category Name\', \'fff\' ),
\'menu_name\' => __( \'Categories\', \'fff\' )
);
register_taxonomy( \'foo_categories\', array( \'foo_articles\' ), array(
\'hierarchical\' => true,
"labels" => $labels,
"singular_label" => __( \'Foo Category\', \'foo\'),
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'foo_category\', \'with_front\' => true )
));
flush_rewrite_rules();
}
Note: 我通过插件设置及其
option_name
是
foo_plugin_slug
(这是客户的想法)
所以请告诉我怎么做。是否有任何挂钩、过滤器或htaccess代码