我有一些WordPress CPT。它们正确的URL应该是/wordpress/triench/trienchpage/,这就是我在管理层管理页面中看到的URL,但是当我单击链接时,我最终会出现IS/WordPress/blog/2010/05/21 /培训页/。

我没有成功地停用插件。有人知道如何保持正确的URL完整吗?

这是我的代码:

<?php
add_action( 'init', 'tv_content_posttype' );
function tv_content_posttype() {
register_taxonomy('content', 
    'training',
    array(
        'hierarchical' => true,
        'label' => 'Content Index',
        'query_var' =>  true, 
        'rewrite' => true
    )
);

register_post_type( 'training',
    array(
        'type' => 'page',
        'labels' => array(
            'name' => __( 'TV Training' ),
            'singular_name' => __( 'TV Training' )
        ),
        'public' => true,
        'rewrite' => array(
            'with_front' => false,
            'slug' => 'training',
        ),
        'hierarchical' => true,
        'query_var' => true,
        'taxonomies' => array( 'content' ),
    )
);
}
有帮助吗?

解决方案

只有一些观察:没有这样的东西 'type' 争论 register_post_type(), ,因此您可以摆脱那条线。第二, 'with_front' => false 告诉WordPress,URL结构应该是 /training/training-page/. /wordpress/ 在这一点上是您告诉它离开的“正面”部分。此外,您无需为post_type添加“分类法”,但是在注册分类学之前,您确实需要注册帖子类型。因此,请尝试以下操作:

<?php
add_action( 'init', 'tv_content_posttype' );
function tv_content_posttype() {
register_post_type( 'training',
    array(
        'labels' => array(
            'name' => __( 'TV Training' ),
            'singular_name' => __( 'TV Training' )
        ),
        'public' => true,
        'rewrite' => array(
            'with_front' => true,
            'slug' => 'training',
        ),
        'hierarchical' => true,
        'query_var' => true,
    )
);

register_taxonomy('content', 
    'training',
    array(
        'hierarchical' => true,
        'label' => 'Content Index',
        'query_var' =>  true, 
        'rewrite' => true
    )
);

}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top