2016-03-22 75 views
2

我已經創建了一組頁面。在第一頁product.php中顯示了所有的自定義類別(標題和圖像)。如果用戶點擊它,那麼它將轉到分類 - 產品_類別頁面,在該頁面中顯示特定類別的產品。現在我想要的是,如果用戶點擊產品,然後進入single-product.php頁面。single-product.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(); ?> 

這是在用戶點擊,那麼它應該去單product.php的地方

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

有人指導我一步一步請

+0

你使用任何特定的商店或? Woocommerce,jigoshop ...? –

+0

沒有。我不使用這些 –

+0

如果'product'是一個CPT,那麼調用'get_permalink()'應該指向'single-product.php'。 –

回答

1

如果您post_type => products那麼你的文件名必須是這樣single-products.php

閱讀本article

而對注意事項(如果頁面還未打開,意味着發生404錯誤)轉至

  1. 管理面板
  2. 設置
  3. 固定鏈接

首先保存固定鏈接爲平原和更新網站的主頁。

然後固定鏈接保存爲post_name,並再次刷新主頁

希望這會幫助你。

1

請嘗試

'post_type' => 'products' 

您發佈的信息類型是「產品」。 而wordpress ruls是「single-{post_type}.php」。 你讓「single-products.php」,並刪除「single-product.php

https://codex.wordpress.org/Post_Type_Templates

+0

是的,它的工作原理。但在單一products.php它顯示的標題不是頁面的內容。 –

+0

您使用get_the_content(); –

+0

您使用「echo get_the_content();」或「the_content();」 –