If you're working with Magento often you'll find sometimes you need to use Magento functions and classes outside of the Magento platform. This can be easily achieved with the following lines of code.
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
// Now you can run ANY Magento code you want
// Change 12 to the ID of the product you want to load
$_product = Mage::getModel('catalog/product')->load(12);
echo $_product->getName();
This was only a quick post but hopefully it will be useful to someone.
Here's an example how to get the site navigation.
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
$_layout = Mage::getSingleton('core/layout');
$_block = $_layout->createBlock('catalog/navigation')->setTemplate('catalog/navigation/left.phtml');
echo $_block->toHtml();







hello ? how to execute this script ? i make a php file, load in magento root category, run it and nothing happend...
Create a file in your Magento root and add the following:
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app(); // Change default to whatever store you want to run
echo "it's worked!";
?>
If the string "It's Worked!" is displayed then it has all worked fine
Hi,thanks for the tutorials. I got a question beyond this tutorial. I'm trying to create a php file that run automatically when the web was loaded. Do you mind to teach me how to achieve it? Thanks a lot.. :d
hai,, give any idea for create static magento page externally.. i want to display menu bars... please help me...
Thanks a million for your job. But it is echoing the english menu, though the default menu is german. Please what do i change to echo the default menu which is german.
Best Regards
Could someone give a quick example on how you would use this code with the block "catalog/product_list"
No matter what I do it tells me that there are no products.
You will need to specifically set the product collection on the list block. For example:
<?php
$products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('status', 1);
$block = Mage::getSingleton('core/layout')->createBlock('catalog/product_list')
->setTemplate('catalog/product/list.phtml')
->setCollection($products);
echo $block->toHtml();
For the first example about gettting the product I wanted, it works. But for the second example I get just empty page. My magento installation is at magento-learn/. I placed the external file at the server root outside magento-learn folder. Why I do not get the site navigations? I am using magento version 7.