Magento: Show Products in any page filter by category attribute

<h2>............................. Top Categories .............................</h2>

<?php
$categories = Mage::getModel('catalog/category')
              ->getCollection()
              ->addAttributeToSelect('*')
              ->addAttributeToFilter('top_category',1)
              ->addIsActiveFilter();
              foreach($categories as $_category)
              {
                     $_productCollection = Mage::getModel('catalog/product')
                     ->getCollection()
                     ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
                     ->addAttributeToSelect('*')
                     ->addAttributeToFilter('category_id', $_category->getId())
                     ->addAttributeToSort('created_at', 'desc');
                     foreach($_productCollection as $_topproduct)
                     {
                       $modell = Mage::getModel('catalog/product');
                       $topproduct_id = $_topproduct->getId();
                       $_topproduct = $modell->load($topproduct_id);
                       $_img=Mage::getModel('catalog/product')->load($topproduct_id);
                            ?>

<div class="top-category-product">

<div class="top-category-product-name"><?php echo $_topproduct->getName(); ?></div>

<div class="top-category-product-image"><a href="<?php echo $_topproduct->getProductUrl() ?>"><img src="<?php echo Mage::helper('catalog/image')-/>init($_img, 'image')->resize(200,200); ?>"></a></div>

</div>

                            <?php
                     }
              }
?>

(more…)