Just something I had to use today that I’m sure will come handy at some point in the future. This particular code was cannibalized from the core code files, to be specific, it is used in the code that generates the sitemap for Magento.
To get the Base Url for the current store you can use:
However, to get the Base Url for a specific store view you can use this. Notice that this code will work from any store view. For example, if you use store views in Magento for multiple languages, you can request the German base url while the system is currently running in the English store view. This all make sense when you have done some multi store code development in the back end… Here it is:
By the way, if you are wondering about the usage of the constant, it basically gives the method an idea of what type of base url you are looking for. In our case we simply wanted the link to the main store page. There are several other types of such links all related to what sort of link you are asking for: Media, JS, Skin, etc. Where each one will give you the proper link to the base folder of what you are looking for. Here is the full list: