Related products on product page in Magento

Move related products from default sidebar location into main product page in Magento.

1. Open catalog.xml, found in

2. In catalog.xml find the catalog_product_view section, around line 205. In the section, remove or comment out:

<block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>

and replace with:

<reference name="content">
<block type="catalog/product_view" name="" template="catalog/product/view.phtml">
<block type="catalog/product_list_related" name="catalog.product.related" as="related" template="catalog/product/list/related.phtml"/>

3. Now in your catalog/product/view.phtml you can print out the related products using

<?php echo $this->getChildHtml('related'); ?>

To edit the look of that list, edit catalog/product/list/related.phtml

Source :

Adding static block into the header area of Magento Site

Steps to add static block into the header area of Magento Site

Steps for adding block in Admin Panel

1. Go to “CMS > Static Blocks”

2. Click the “Add New” button.

3. Enter the Block Title like “Header Menu”

4. Enter identifier like enter “header-menu”. (all letters will be small)

5. Select the store view.

6. Set status to “Enabled”.

7. Add you block content.

8. Click on “Save Block” button.

Steps for changing in page.xml file

1. Open file “/app/design/frontend/default/yourtheme/layout/page.xml” file.

2. Find header block


<label>Page Header</label>

3. Now add the following block in just before the closing block </block> tag
<block type=”cms/block” name=”header-menu”><action method=”setBlockId”><block_id>header-menu</block_id></action></block>

Steps for changing in header.phtml file

[sourcecode language=”plain”]
1. Open file “/app/design/frontend/default/yourtheme/page/html/template/header.phtml” file.
2. Just add the following code where you want to add the block
<?php echo $this->getChildHtml(‘header-menu’) ?>

Source :

How to remove the ‘Shop By’ box from the left column in Magento

To activate and deactivate widgets in Magento like the Newsletter option, it’s pretty easy. You just go to System/Configuration/Advanced and select ‘disable’ next to the ‘Mage_Newsletter’ item.

But what if you want to disable something that has no apparent widget control? I couldn’t find a widget that controlled the ‘Shop By’ option in the left column. If there is a widget that controls this, please let me know!

The first way to remove an item – edit the code from the referenced PHTML file

What I did was to first identify the name of the DIV that contained it .To do this, visit a page containing the item on your testing or live server, select ‘view source’, copy the source code in its entirety and paste it into a new, blank HTML Dreamweaver file. Working in Split View, you can click on DIVs in the Design Pane and see what they are called in the Code Pane.

I established that the code in question was within the “block block-layered-nav” DIV. In Dreameaver Files, select the app/design/frontend/base directory and perform a search for “block block-layered-nav” in the source code of all selected files. Click ‘Find All’.

The search showed that two files contained this css string – the view.phtml and left.phtml files. Upon inspection, the view.phtml file contained the ‘Shop By’ title, so this was the one to edit. You could either comment out all the PHP and HTML, or (as I did) empty the file after making a copy of it for later reinstatement if required.

Upload the file to app/design/frontend/default/yourtheme/template/catalog/layer and the item should disappear from the left column.

If you are wondering why we retrieved the view.phtml from the Base theme rather than your theme, it’s because sometimes not all the phtml files exist in a theme, and when this happens Magento defaults to the Base theme to find one. By uploading it to the same location in your theme, it overrides the default Base version.

Of course, if you have a view.phtml already in your theme, edit that one.

The second way to remove an item – edit the code from the referencing XML file

Now you know where the code resides, you can perform a new search of the app/design’frontend/base directory for the filename, ‘view.phtml’. This showed quite a few files referencing view.phtml, but only two which were referenced view.phtml in the layer directory: catalog.xml and catalogsearch.xml.

Just focusing on the catalog.xml file (which affects more pages), locate the reference of layer/view.phtml in the code. It appeared just once on line 115. Comment out the code that references the file, replacing this:

with this:

Save the catalog.xml file to the corresponding directory in your theme (if it doesn’t already exist): app/design/frontend/default/yourtheme/layout

Now the Shop By option should have left the site.

Source :

How to get the login & logout url in magento?

Following is the code to get the login & logout link.

//check the user is loggedon or not
if (! Mage::getSingleton('customer/session')->isLoggedIn()){
//if user logged on show the logout link - add this code within anchor tag
echo Mage::helper('customer')->getLoginUrl();
//if user is not logged on yet show the login link - add this code within anchor tag
echo Mage::helper('customer')->getLogoutUrl();

Here are more variable’s that may you need to get the customer data on the frontend.

bool customerHasAddresses ()
string getAccountUrl ()
Mage_Customer_Model_Customer getCurrentCustomer ()
Mage_Customer_Model_Customer getCustomer ()
string getCustomerName ()
string getDashboardUrl ()
string getEditPostUrl ()
string getEditUrl ()
string getEmailConfirmationUrl ([string $email = null])
string getForgotPasswordUrl ()
Mage_Customer_Model_Entity_Group_Collection getGroups ()
string getLoginPostUrl ()
string getLoginUrl ()
string getLogoutUrl ()
string getRegisterPostUrl ()
string getRegisterUrl ()
bool isConfirmationRequired ()
bool isLoggedIn ()
bool isRegistrationAllowed ()
Source :

Remove magento footer links.

If you want to remove the “Help Us to Keep Magento Healthy – Report All Bug” from footer, navigate to


of your theme assuming that you are using default magento theme . Otherwise navigate to your related theme file and remove the following line

<p class="bugs"><?php echo $this->__('Help Us to Keep Magento Healthy') ?> - <a href="" onclick="'_blank'"><strong><?php echo $this->__('Report All Bugs') ?></strong></a> <?php echo $this->__('(ver. %s)', Mage::getVersion()) ?></p>

If you want to remove the menus seens in the footer like “Site Map, Search Terms, Advanced Search, Orders and Returns, Contact Us” Then remove the following code from page.xml

<block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>

Query in Magento

Magento have own standard of query,

    $products   = $product->setStoreId($storeId)->getCollection()
	->addAttributeToFilter('featured', array('Yes'=>true))
	->addAttributeToSelect(array('name', 'price', 'small_image'), 'inner');

If we want to add the other condition like
for random case,

$products->getSelect()->order(new Zend_Db_Expr('RAND()'));

for to limit


Vi commands: Simple and Quick tutorial

VI is a display oriented interactive text editor originally created for the Unix operating system. It is available by default on all UNIX systems. It is supplied with all Linux distributions.

Here is a simple and quick VI command tutorial.

Note: VI commands are CASE SENSITIVE.


There are two modes in vi: command mode and insert mode.
All vi commands work on command mode.

– Hitting Esc will put you in command mode
– Hitting i and a in command mode will put you in insert mode.
– Hitting i will insert text before the cursor
– Hitting a will append text after the cursor

Creating new file

– Open terminal (In Ubuntu, press: CTRL + ALT + T)
– Type the following command to create new file named hello.txt:
vi hello.txt

vi -r filename = recover filename that was being edited when system crashed

Saving file

– After you enter some text to your file, press Esc
– Then type “:w” (without quote)

Exit vi

– press Esc
– type “:q” (without quote)

:wq = save any changes and quit vi
ZZ = save any changes and quit vi
:q! = quit vi even though latest changes have not been saved

Moving Cursor

– h j k l will move cursor left, down, up, right respectively
– 0 (zero) will move cursor to start of current line
– $ will move cursor to end of current line
– w e b will move forward one word, forward to next end of a word, and back one word, respectively
– :0 (zero) or 1G will move cursor to first line in file
– :n or nG will move cursor to line n
– :$ or G will move cursor to last line in file

Moving through screen

CTRL f will move forward one screen
CTRL b will move backward one screen

Deleting Text

x = delete single character
dd = delete entire current line
dw = delete single word beginning with character under cursor
db = delete word backward
D = delete the remainder of the line, starting with current cursor position
d$ = delete from cursor to end of line (same as D)
d0 = delete from cursor to beginning of line
dL = delete from current line to end of screen
dG = delete from current line of end of file
d) = delete complete sentence forward
d( = delete complete sentence backwards

Undo and Redo

u = undo last command
. (dot) = redo/repeat last command

Copy and Paste

yy = copy current line
yw = copy word forward
yb = copy word backward
Y = copy the remainder of the line, starting with current cursor position
y$ = copy from cursor to end of line (same as Y)
y0 = copy from cursor to beginning of line
yL = copy from current line to end of screen
yG = copy from current line to end of file
y) = copy from cursor to start of sentence
y( = copy from cursor to end of sentence
p (lowercase) = paste to the line below the current line
P (uppercase) = paste to the line above the current line
Lines and words deleted from dd and dw can also be pasted.


/string = search forward for occurence of string
?string = search backward for occurence of string
n (lowercase) = find the next occurence of the search
N (uppercase) = find the previous occurence of the search

Find and replace

:%s/foo/bar/g = replace all occurences of foo with bar in the entire file

s = substitute
g = global, i.e. the action should be performed for all instances of a string found on any given line
% sign = “Do this for all lines in this buffer.”

Other find and replace commands:-

:s/foo/bar/ = replace the first occurrence of the word foo on the current line with the word bar.
:s/foo/bar/g = replace all occurrences of the word foo on the current line with the word bar.
:%s/foo/bar/g = replace all occurrences of the word foo in the current file with the word bar.
:%s/foo//g = delete all occurrences of the word foo in the current file.

Reading and writing to file

– Open terminal
– Type vi and hit enter
– :r filename = read file named filename
– :w newfile = write the recently read content to newfile

Set commands

:set nu = display line numbers
:set nonu = cancel line number display
:set ts=4 will set the number of spaces used to display the tab character to 4
:set ic = make string searches with / ignore cases
Example: After :set ic using /foobar will find foobar as well as FooBaR

Shell operations

We can execute any shell command inside vi itself.

:!command = execute command without leaving vi
Example: :!date = display date

We can start a new command shell inside vi itself.

:sh = start a new command shell inside vi
Type exit to leave that shell and return back to vi.


Copied from :

Custom image size and autocrop options

WordPress provides different sizes of images , the size of the uploaded image can be edited form Setting > Media and give the required value .But sometime we may need other sizes imaged too so for that purpose we can use the function.php of the theme for custom options. I found it from

Just add

add_image_size($name, $width, $height, $cropBoolean);

For example : add_image_size('featuredImageCropped', 250, 200, true);