我已經創建了一組頁面。在第一頁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=""
有人指導我一步一步請
你使用任何特定的商店或? Woocommerce,jigoshop ...? –
沒有。我不使用這些 –
如果'product'是一個CPT,那麼調用'get_permalink()'應該指向'single-product.php'。 –