Actually I want limited no of products in page when the limit exceeds it should show products along with more button i.e, link. for eample products per page is 6 and if products are more than 6 means it should display more link button. How we can resolve it.
Below is my code,
<?php
if ($child['id'] == $product['parent_id']) {
$count = 1;
if ($count <= 1) {
$count++;
?>
<li>
<a href="<?php echo $product['href']; ?>" ><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" />
<p><?php echo $product['name']; ?></p></a>
</li>
<?php
}
}
?>
<span><a href="<?php echo $child['href']; ?>">More..</a></span>
I'm guessing there's a loop involved here, above your code. You're instantiating the $count
variable everytime. Do it like this:
<?php $count = 1; ?>
<?php for(/*some loop*/) {?>
<?php if($child['id'] == $product['parent_id']){?>
<?php if($count <= 6) {
$count++;
?>
<li>
<a href="<?php echo $product['href'];?>" ><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" />
<p><?php echo $product['name']; ?></p></a>
</li>
<?php } else {
?>
<span><a href="<?php echo $child['href']; ?>">More..</a></span>
<?php
break;
}?>
<?php }?>
<?php }?>
The last line of your code should probably have a conditional statement determining whether it should be displayed:
<?php if ($count > 6){ ?>
<span><a href="<?php echo $child['href']; ?>">More..</a></span>
<?php } ?>
EDIT: As others have pointed out, without a loop, your $count
variable isn't much use...
Try This
<?php if($child['id'] == $product['parent_id']){?>
<?php $count = 1; /// this should be out side of the loop
$count++;
?>
<li>
<a href="<?php echo $product['href'];?>" ><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" />
<p><?php echo $product['name']; ?></p></a>
</li>
<?php if($count > 6) { ?>
<span><a href="<?php echo $child['href']; ?>">More..</a></span>
<?php
break; //it will stop your loop to create more records
}?>
Another solution is, if you are using database to display products then you can add limit in query to avoid full query e.g
SELECT * FROM prod_tbl LIMIT 0,6