2017-06-07 22 views
0

私は各国に異なる製品を提供しているので、私のウェブサイトのショップセクションを米国と英国のセクションに分けようとしています。国ごとにサブフォルダにリダイレクト

私はサブフォルダを使用したいと思います。 /usまたは/ukですが、顧客が店舗セクションに入る(ショップ、カテゴリまたは商品をクリックした)ときのみです。

shop.サブドメインを作成し、適切なサブフォルダにIPベースのリダイレクトを有効にすると、shop.サブドメインに入ることが最善の方法だと思います。

私は国別セレクタポップアップ(IPでリダイレクトする必要はありません)を使用できますが、2つの別個のウェブサイトを必要とせず、ブログ投稿を/usまたは/ukのサブフォルダに入れたくありません。

その理由は、ユーザーがshop.セクションをクリックしたときにのみリダイレクトを有効にするためです。

私はWorpressを使用していますので、動作するプラグインがあれば使用できます。

サブフォルダ(/shop/uk/product/ukなど)のみを使用しなければならない場合、私はそれを実行できますが、私の特定の要件に適用されるアドバイスは見つかりません。

答えて

0

カスタムポストタイプの「ショップ」を作成し、カスタム分類を作成します。 次に、各国ごとに新しいカスタム分類を追加し、それをカスタムの投稿タイプ「ショップ」に割り当てます。

そうのようなのfunctions.phpでカスタムポストタイプの登録:登録時に書き換えルールに%/%の国を使用するためには

add_action('init', 'build_taxonomies', 0); 
function build_taxonomies() { 
    register_taxonomy('countries', 'shops', array('hierarchical' => true, 'label' => 'Countries', 'query_var' => true, 'rewrite' => array('slug' => 'shops', 'with_front' => false))); 
} 

:カスタム分類を登録すると

add_action('init', 'custom_post_types', 0); 
function custom_post_types() { 

//shops 
    register_post_type('shops', 
     array(
      'labels' => array(
       'name' => __('Shops'), 
       'singular_name' => __('Shops'), 
       'all_items' => __('All Shops'), 
      ), 
      'capabilities' => array(
       'edit_post'   => 'update_core', 
       'read_post'   => 'update_core', 
       'delete_post'  => 'update_core', 
       'edit_posts'   => 'update_core', 
       'edit_others_posts' => 'update_core', 
       'delete_posts'  => 'update_core', 
       'publish_posts'  => 'update_core', 
       'read_private_posts' => 'update_core' 
      ), 
      'taxonomies' => array('countries'), 
      'menu_position' => 5, 
      'public' => true, 
      'has_archive' => false, 
      'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt'), 
      "rewrite" => array(
       "slug"=>'news/%countries%', 
       "with_front" => false 
      ), 
     ) 
    ); 
} 

をあなたのカスタム投稿タイプは、WordPressにその意味を伝える必要があります。あなたはそうそうする:

add_filter('post_type_link', 'wpa_shops_permalinks', 1, 2); 
function wpa_shops_permalinks($post_link, $post){ 
    if (is_object($post) && $post->post_type == 'shops'){ 
     $terms = wp_get_object_terms($post->ID, 'countries'); 
    if($terms){ 
     return str_replace('%countries%' , $terms[0]->slug , $post_link); 
    } 
} 
return $post_link; 
} 
関連する問題