0

I am currently displaying items from a selected category in a slider in the following way:

    $cat_id = $homepage["homeproductstype_{$homepage['amount']}_3"];
    $_products = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToSelect(array('name', 'price', 'small_image', 'short_description'), 'inner')
    ->addAttributeToSelect('special_price')
    ->addAttributeToSelect('status')
    ->addCategoryFilter(Mage::getModel('catalog/category')->load($cat_id));

What I would like to do here though, is to have them displayed by ID in ASC order.

What is the best way to have this achieved?

1
  • I think by default it is ordered by id , but if it is not than you can try something like this ->setOrder('id', "asc") at the end of query. Commented May 30, 2013 at 4:22

2 Answers 2

1

You can use addAttributeToSort() function to sort your collection based on id.

Add this to your collection addAttributeToSort(’entity_id’, ‘asc’);

See magento collection page for more info http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, I just figured this method out.
0

Sorted it out by adding

    ->addAttributeToSort('entity_id', 'asc'); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.