wordpress虚拟页面子目录

时间:2014-04-25 03:02:47

标签: wordpress

我有一个wp网站,其中包含产品以及其他服务。 我希望产品页面的名称为product-catalog,作为url的一部分。

有没有办法在不必为这些页面创建物理子目录的情况下执行此操作。

永久链接可以选择吗?

感谢 maggs

2 个答案:

答案 0 :(得分:0)

是的,您可以使用自定义永久链接结构 使用设置>下的%postname%编写所需的结构永久链接>自定义永久链接

enter image description here

答案 1 :(得分:0)

您可以创建一个帖子类型“product-catalog”,然后像这样重写您的网址。

function codex_custom_init() {
    $args = array(
      'public' => true,
      'label'  => 'Product'
    );
    register_post_type( 'product-catalogue', $args );
    flush_rewrite_rules();  
}
add_action( 'init', 'codex_custom_init' );

function prefix_product_catalogue_rewrite_rule() {
    add_rewrite_rule( 'product-catalogue/([^/]+)/about', 'index.php?product-catalogue=$matches[1]&about=yes', 'top' );

}

add_action( 'init', 'prefix_product_catalogue_rewrite_rule' );

// create single.php like template for your custom post type ie, product-catalogue
function prefix_url_rewrite_templates() {

    if ( get_query_var( 'about' ) && is_singular( 'band' ) ) {
        add_filter( 'template_include', function() {
            return get_template_directory() . '/single-product-catalogue.php';
        });
    }


}

add_action( 'template_redirect', 'prefix_url_rewrite_templates' );

将此代码粘贴到主题文件夹的function.php中。

相关问题