Under Configuration -> Inventory -> Display Out of Stock Products I have set it to Yes because out of stock products are accessible by Search Engines though I don't want the out of stock products to show up in Upsell section. Is there any way to achieve this by applying filters? Below is the entire code of my upsell.phtml.
<?php if (count($this->getItemCollection()->getItems())): ?>
<div class="collateral-box up-sell">
<div class="head"><h4><?php echo $this->__('You may also be interested in the following product(s):') ?></h4></div>
<table cellspacing="0" class="generic-product-grid catalog-listing" id="upsell-product-table">
<?php // $this->setColumnCount(4); // uncomment this line if you want to have another number of columns. also can be changed in layout ?>
<?php $this->resetItemsIterator() ?>
<?php for ($_i = 0; $_i < $this->getRowCount(); $_i++): ?>
<tr>
<?php for ($_j = 0; $_j < $this->getColumnCount(); $_j++): ?>
<?php if ($_link = $this->getIterableItem()): ?>
<?php $_link = Mage::getModel('catalog/product')->load($_link->getId()); ?>
<td>
<p class="product-image"><a href="<?php echo $_link->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_link, 'small_image')->resize(125) ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($_link->getName()) ?>" /></a></p>
<h5><a href="<?php echo $this->getUrl($_link->getUrlPath()) ?>"><?php echo $this->htmlEscape($_link->getName()) ?></a></h5>
<?php //echo $this->getPriceHtml($_link, true) ?>
<?php //echo $this->getReviewsSummaryHtml($_link) ?>
</td>
<?php else: ?>
<td class="empty-product"> </td>
<?php endif; ?>
<?php endfor; ?>
</tr>
<?php endfor; ?>
</table>
<script type="text/javascript">decorateTable('upsell-product-table')</script>
</div>
<?php endif ?>