title: Add sort order to featured products in magento
body: <p>I am using the following piece of code to allow users to set featured products that will display on the homepage but I need to extend this so that they can also dictate the sort order of the items. By default it displays the producst in the order they were added to Magento.</p>
  
  <p>To do this I have created a attribute called "sort_order" that allows the users to add a numerical value that will dictate the sort order when displayed on the homepage. For example if I have 4 products then the sort order could be displayed as followed</p>
  
  <p>product1 - sort order 3
  product 2 - sort order 1
  product 3 - sort order 2
  product 4 - sort order 4</p>
  
  <p>I have been trying all morning get this working. I presume I need to create an array of some sort that allows me to then order the products as dicated by the attribute "sort_order" but i'm not getting anywhere</p>
  
  <p>If anyone can offer some advice I would be very grateful</p>
  
  <pre><code>  &lt;div id="home-featured"&gt;
    &lt;h2&gt;&lt;?php echo $this-&gt;__('Featured') ?&gt;&lt;/h2&gt;
    &lt;?php
          // some helpers
          $_helper = $this-&gt;helper('catalog/output');
          $storeId = Mage::app()-&gt;getStore()-&gt;getId();
          $catalog =  $this-&gt;getLayout()-&gt;createBlock('catalog/product_list')-&gt;setStoreId($storeId);
  
          // get all products that are marked as featured
          $collection = Mage::getModel('catalog/product')-&gt;getCollection();
          $collection-&gt;addAttributeToSelect('featured_product');
          $collection-&gt;addFieldToFilter(array(
              array('attribute' =&gt; 'featured_product', 'eq' =&gt; true),
          ));
  
          // if no products are currently featured, display some text
          if (!$collection-&gt;count()) :
      ?&gt;
    &lt;p class="note-msg"&gt;&lt;?php echo $this-&gt;__('There are no featured products at the moment.') ?&gt;&lt;/p&gt;
    &lt;?php else : ?&gt;
    &lt;div class="category-products"&gt;
      &lt;?php
          $_collectionSize = $collection-&gt;count();
          $_columnCount = 4;
          $i = 0;
  
          foreach ($collection as $_product) :
          $_product = Mage::getModel('catalog/product')-&gt;setStoreId($storeId)-&gt;load($_product-&gt;getId());
      ?&gt;
      &lt;article&gt;
        &lt;div class="product-image"&gt;&lt;a href="&lt;?php echo Mage::helper('fullurl')-&gt;getFullProductUrl($_product); ?&gt;" title="&lt;?php echo $this-&gt;stripTags($this-&gt;getImageLabel($_product, 'small_image'), null, true) ?&gt;" &gt;&lt;img src="&lt;?php echo $this-&gt;helper('catalog/image')-&gt;init($_product, 'small_image')-&gt;keepFrame(false)-&gt;resize(170); ?&gt;" width="170" alt="&lt;?php echo $this-&gt;stripTags($this-&gt;getImageLabel($_product, 'small_image'), null, true) ?&gt;" /&gt;&lt;/a&gt;&lt;/div&gt;
        &lt;div class="featured-info"&gt;
          &lt;h3&gt;&lt;a href="&lt;?php echo Mage::helper('fullurl')-&gt;getFullProductUrl($_product); ?&gt;" title="&lt;?php echo $this-&gt;stripTags($_product-&gt;getName(), null, true) ?&gt;"&gt;&lt;?php echo $_helper-&gt;productAttribute($_product, $_product-&gt;getName(), 'name') ?&gt;&lt;/a&gt;&lt;/h3&gt;
          &lt;p&gt;&lt;?php echo $_helper-&gt;productAttribute($_product, $_product-&gt;getShortDescription(), 'short_description ') ?&gt;&lt;/p&gt;
          &lt;span class="link-dreambuilder"&gt;&lt;a href="&lt;?php echo $this-&gt;helper('wishlist')-&gt;getAddUrl($_product) ?&gt;" &gt;&lt;?php echo $this-&gt;__('+ Add to Dream Builder') ?&gt;&lt;/a&gt;&lt;/span&gt; &lt;/div&gt;
      &lt;/article&gt;
      &lt;?php endforeach ?&gt;
    &lt;/div&gt;
    &lt;?php endif ?&gt;
  &lt;/div&gt;
  </code></pre>