【发布时间】:2015-05-14 12:09:11
【问题描述】:
当我们将永久链接设置为 Post name 并转到 wordpress 任何默认帖子时,例如“Testing 123”单页,其链接如下所示
localhost/foo_articles/testing-123
现在,当我们将永久链接更改为 Custom Structure 并设置像 %category%/%postname% 这样的值时,链接看起来像这样
http://localhost/foo_articles/testing/testing-123/
测试是我的类别 slug
现在我的问题的主要部分是
我制作了一个插件,在其中创建了一个帖子类型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_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();
}
注意:我通过插件设置更改我的帖子类型 slug,它的 option_name 是 foo_plugin_slug(这是客户的想法)
所以请告诉我我该怎么做。是否有任何钩子或过滤器或 htaccess 代码
【问题讨论】:
-
这不属于wordpress.stackexchange.com吗?一些非常有才华的人正在监视该网站。
-
非常有用的评论>:(
-
发布单页 =
http://localhost/foo_articles/foo_articles/how-to-reduce-the-intake-of-junk-food-in-children/是吗?foo_articlesx 2? [quote] 现在我的问题是如何设置链接,当用户设置永久链接自定义结构并设置像 %category%/%postname% 这样的值时,我的链接也会像上面的默认帖子单页一样改变。[/quote] -
$foo_slug = 'foo_articles'; $foo_slug = get_option('foo_plugin_slug');不清楚这里的意图。 -
$foo_slug = get_option('foo_plugin_slug');是一个帖子类型的 slug,用户可以更改
标签: php wordpress permalinks