【问题标题】:Wordpress: Custom Post Type with different base URL from Standard Post TypeWordpress:具有与标准帖子类型不同的基本 URL 的自定义帖子类型
【发布时间】:2016-03-19 10:36:03
【问题描述】:

我在博客旁边创建了一个名为 Products 的自定义帖子类型。我的博客存档网址是

www.mywebsite.com/blog

博客文章看起来像

www.mywebsite.com/blog/postName.

我的产品自定义帖子类型 URL 看起来像

www.mywebsite.com/blog/products. 

我想从 url 中删除博客目录并使其看起来像

www.mywebsite.com/products/productName

我可以通过从我在 Wordpress 中的永久链接中删除 /blog/%postname% 来做到这一点,但是我的博客帖子看起来像:www.mywebsite.com/postName,没有博客目录。

如何在没有博客目录的情况下为我的自定义帖子类型提供一个干净的 URL?

【问题讨论】:

  • /blog/ 是您的 WP 网站的主页/根 URL 吗?
  • @rnevius 我创建了一个名为 blog 的页面,并在 Settings -> Reading -> A Static Page -> Post Page 下进行了设置。我的主页是我创建的名为 Home 的静态页面。

标签: php wordpress .htaccess url-rewriting


【解决方案1】:

也许对你有帮助。做这样的事--

$labels      = array(
                'name'               => $plural_title,
                'singular_name'      => $title,
                'add_new'            => __( 'Add New', 'adeq' ),
                'add_new_item'       => __( 'Add New', 'adeq' ) .' '. $title,
                'edit_item'          => __( 'Edit', 'adeq' ) .' '. $title,
                'new_item'           => __( 'New', 'adeq' ) .' '. $title,
                'all_items'          => __( 'All', 'adeq' ) .' '. $plural_title,
                'view_item'          => __( 'View', 'adeq' ) .' '. $title,
                'search_items'       => __( 'Search', 'adeq' ) .' '. $plural_title,
                'not_found'          => $plural_title . __( ' not found', 'adeq' ),
                'not_found_in_trash' => $plural_title . __( ' not found in Trash', 'adeq' ),
                'parent_item_colon'  => '',
                'menu_name'          => $plural_title
                );

            if ( !empty( $args['labels_override'] ) ) {
                $labels = wp_parse_args( $args['labels_override'], $labels );
            }

            $defaults = array(
                'labels'             => $labels,
                'public'             => true,
                'publicly_queryable' => true,
                'show_ui'            => true,
                'show_in_menu'       => true,
                'show_in_nav_menus'  => true,
                'query_var'          => true,
                'has_archive'        => true,
                'hierarchical'       => false,
                'menu_position'      => null,
                'menu_icon'          => null,
                'supports'           => array( 'title', 'thumbnail', 'editor' )
                );

            $args = wp_parse_args( $args, $defaults );
            $this->post_types[ $post_type ] = $args;
        }
    }

Your Permalink will show like --

【讨论】:

    猜你喜欢
    • 2015-12-22
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    相关资源
    最近更新 更多