Scenario: I have a template part loop-product.php
which i am calling from home.php
, taxonomy.php
and a page template template-products.php
. Inside that template part loop-product.php
file i am setting the number of columns by checking is_home()
conditionals.
Problem:
The conditional works fine for homepage, taxonomy page but its still set on the page template. On the product item i have added a class columns-$cols
so you can check it on the site. Its showing columns-4
on the product template page where it suppose to show columns-3
.
<?php
$j = 1;
if(is_home()){
$cols = 4;
}else{
$cols = 3;
}
if(have_posts()):while(have_posts()):the_post();
// getting thumbnail image here
?>
<div class="product-item <?php echo 'columns-'.$cols ?>" <?php if($j%$cols == 0){ echo 'style="margin-right:0;"'; } ?>>
<a href="<?php the_permalink(); ?>">
<span class="product-img">
<img src="<?php echo $img[0]; ?>" width="100" height="75" alt="<?php the_title(); ?>">
</span>
<span class="desc">
<h2><?php the_title(); ?></h2>
<?php
if($price): ?>
<span class="price">Price: <?php echo $price; ?> BDT</span>
<?php endif; ?>
</span>
</a>
</div>
<?php if($j%$cols == 0){ echo '<div class="clear"></div>'; } ?>
<?php $j++; endwhile; endif; ?>
<div class="clear"></div>
Check the site here http://computercarebd.com/ Appreciate your time. Thanks!
Page template code: http://pastebin.com/CzRgzzVF