I have created a set of pages. In first page product.php all the custom categories are shown (title and image). If a user clicks on it then it moves to the taxonomy-product_categories page where products are shown of the specific category. Now i want that if user clicks on the product then it goes to single-product.php page.
code is here
<?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(); ?>
this is the place where user clicks then it should go to single-product.php
<a href="#"><img src="<?php echo $the_url[0] ?>" title=""
Somebody guide me step by step please
If your post_type => products
Then your file name must be like this single-products.php
Read this article
And for precautions (if the page not open yet. means give 404 error) go to
- admin panel
- settings
- permalinks
First save permalinks as plain and refresh your site home page.
Then save permalinks as post_name
and again refresh your home page
Hope this will help you.