Magento: Add Custom “Sort By” Drop Down menu options

Hi All, today I'm discussing about the add custom option in "Sort By" drop down in Magento product listing page.
In Magento on the product listing page there is the Options "Sort By" in the toolbar, by default there is only Price,Position and Name option exists in drop down.

If you want to add some more Sort By Filter in the drop down( like price high to low, price low to high ,Sort By Name A-Z,Sort By Name Z-A ). Below steps will help you to understand and add your own custom sort by option in drop down in magento in product listing page.

Step 1 – Go to below file :
app/design/frontend/default/yourtheme/template/catalog/product/list/toolbar.phtml or you can find this file app/design/frontend/base/default/template/catalog/product/list/toolbar.phtml open the file in the editor and search for the below code

<fieldset>
  <label><?php echo $this->__('Sort by') ?></label>
  <select onchange="setLocation(this.value)">
    <?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
    <option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>> <?php echo $_order ?> </option>
    <?php endforeach; ?>
  </select>
  <?php if($this->getCurrentDirection() == 'desc'): ?>
  <a href="<?php echo $this->getOrderUrl(null, 'asc') ?>"> <img src="<?php echo $this->getSkinUrl('images/sort_desc_arrow.gif') ?>" alt="<?php echo $this->__('Set Ascending Direction') ?>" /></a>
  <?php else: ?>
  <a href="<?php echo $this->getOrderUrl(null, 'desc') ?>"> <img src="<?php echo $this->getSkinUrl('images/sort_asc_arrow.gif') ?>" alt="<?php echo $this->__('Set Descending Direction') ?>" /></a>
  <?php endif; ?>
</fieldset>

Step 2 – Replace or use below code as per your requirement :

<option value="<?php echo $this->getOrderUrl('name', 'asc') ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>> Name A-Z </option>

<option value="<?php echo $this->getOrderUrl('name', 'desc') ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>> Name Z-A </option>

<option value="<?php echo $this->getOrderUrl('price', 'asc') ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>> Price - Low to High </option>

<option value="<?php echo $this->getOrderUrl('price', 'desc') ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>> Price - High to Low </option>

<option value="<?php echo $this->getOrderUrl('entity_id', 'desc') ?>"<?php if($this->isOrderCurrent('entity_id') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>> Newest Products </option>

<option value="<?php echo $this->getOrderUrl('entity_id', 'asc') ?>"<?php if($this->isOrderCurrent('entity_id') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>> Oldest Products </option>

Step 4 : Save the file and refresh your browser cache then you will see the changes.

Hope this helps.Happy Coding!!!!