2016-03-22 12 views
2

私は一連のページを作成しました。最初のページproduct.phpにはすべてのカスタムカテゴリが表示されます(タイトルと画像)。ユーザーがそれをクリックすると、taxonomy-product_categoriesページに移動し、特定のカテゴリの製品が表示されます。ユーザーが製品をクリックするとsingle-product.phpページに移動します。単一製品.phpが開かない

コードはここに

<?php 
get_header(); 
$slug = get_queried_object()->slug; // get clicked category slug 
$name = get_queried_object()->name; // get clicked category name 
$tax_post_args = array(
    'post_type' => 'products', // your post type 
    'posts_per_page' => 999, 
    'orderby' => 'id', 
    'order' => 'ASC', 
    'tax_query' => array(
     array(
      'taxonomy' => 'product_categories', // your taxonomy 
      'field' => 'slug', 
      'terms' => $slug 
     ) 
    ) 
); 
?> 
<div id="main-wrap"> 
    <div class="container"> 
     <?php 
     $counter = 1; 
     $tax_post_qry = new WP_Query($tax_post_args); 
     if ($tax_post_qry->have_posts()) { 
      while ($tax_post_qry->have_posts()) { 
       $tax_post_qry->the_post(); 
       $the_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $type); 
       //var_dump($the_url); 


       if ($counter % 4 == 0) { 
        echo '<div class="row product-gallery">'; 
       } 
       ?> 
       <div class="col-sm-3"> 
        <div class="product-warp"> 
         <div class="product"> 
          <a href="#"><img src="<?php echo $the_url[0] ?>" title="" alt=""></a> 
         </div> 
         <div class="product-name"> 
          <h5> 
           <a href=""> 
            <?php echo get_the_title(); 
            ; ?> 
           </a> 
          </h5> 
         </div> 
        </div> 
       </div> 
       <?php 
       if ($counter % 4 == 0) { 
        echo '</div>'; 
       } 
       ?> 

       <?php 
      } 
     } 
     ?> 
    </div> 
</div> 
<?php get_footer(); ?> 

これは、ユーザが、それは

<a href="#"><img src="<?php echo $the_url[0] ?>" title="" 

誰かがステップバイステップで私を導いシングルproduct.phpに行く必要がありますクリックする場所ですしてください

+0

あなたは特定のショップを使用していますか? Woocommerce、ジグソップ...? –

+0

番号。私はこれらを使用していません –

+0

'product'がCPTの場合、' get_permalink() 'を呼ぶだけで' single-product.php'を指すはずです。 –

答えて

1

を削除する場合(このarticle

や注意事項のためを読みますページがまだ開かれていないことを意味する404エラー)

  1. 管理パネル
  2. 設定
  3. パーマリンク

まず、プレーンとしてパーマリンクを保存し、あなたのサイトのホームページを更新。

その後post_nameとしてパーマリンクを保存して、もう一度あなたのホームページが

をリフレッシュするには、これはあなたを助けることを願っています。

1

お試しください。

'post_type' => 'products' 

お客様の投稿タイプは「商品」です。 そしてwordpress rulsは "single-{post_type}.php"です。 あなたが「single-products.php」を作り、あなたのpost_type => productsその後、あなたのファイル名がこのsingle-products.php

のようでなければならない場合は、「single-product.php

https://codex.wordpress.org/Post_Type_Templates

+0

はい、動作します。 single-products.phpには、ページの内容ではなくタイトルが表示されます。 –

+0

get_the_content()を使用します。 –

+0

"echo get_the_content();"を使用します。または "the_content();" –

関連する問題