Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Moving category images to the header
 
randomutterings
Jr. Member
 
Total Posts:  19
Joined:  2008-02-28
 

I’m trying to move the category images to the header section of my layout.  I also have a default image I want to use in that place if a category image wasn’t uploaded.  I tried putting this code into the header.phtml but it shows a blank page.  What am I missing?

<?if($_imageUrl=$this->getCurrentCategory()->getImageUrl()):?>
  
<p><img src="<?=$_imageUrl?>alt="<?=$this->getCurrentCategory()->getName()?>" width="475"/></p>
<?else:?>  
  
<p><img src="<?=$this->getSkinUrl('images/header_bg.jpg')?>"></p>
<?endif;?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
randomutterings
Jr. Member
 
Total Posts:  19
Joined:  2008-02-28
 

Hello, is anyone there?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nowayjose
Jr. Member
 
Total Posts:  2
Joined:  2008-02-05
 

I would really like to know if this is possible as well. I’m trying to move the category image to the header.

 
Magento Community Magento Community
Magento Community
Magento Community
 
leruss
Jr. Member
 
Total Posts:  21
Joined:  2008-08-13
 

Hi,

Here’s my solution, but not working completely, so help wanted please smile

Create a cat_img.phtml file in template/catalog/category with the following code :

<?php if($_imageUrl=$this->getCurrentCategory()->getImageUrl()): ?>
        
<p><img src="<?php echo $_imageUrl ?>" alt="<?php echo $this->htmlEscape($this->getCurrentCategory()->getName()) ?>" /></p>
    
<?php endif; ?>

In layout/page.xml add the line :
<block type="catalog/category_view" name="category.image" template="catalog/category/cat_img.phtml" />
inside the <block type="page/html_header" name="header" as="header"> tag :

<block type="page/html_header" name="header" as="header">
                <
block type="customer/form_login" name="mini_login" template="customer/form/mini.login.phtml" />
                <
block type="page/template_links" name="top.links" as="topLinks"/>
                <
block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
                
                <
block type="catalog/category_view" name="category.image" template="catalog/category/cat_img.phtml" />

                <
block type="core/text_list" name="top.menu" as="topMenu"/>
            </
block>

In template/page/html/headers.phtml replace :

<h1 id="logo"><a href="<?php echo $this->getUrl('') ?>"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a></h1>
by
<h1 id="logo"><?php echo $this->getChildHtml('category.image'?></h1>

Unfortunately, it works for all the categories / subcategories / products views, BUT not for the home page, I have this error :

Fatal error: Call to a member function getMetaTitle() on a non-object in C:\apache\htdocs\magento\app\code\core\Mage\Catalog\Block\Category\View.php on line 37

I don’t want to touch the core code of Magento, so how could I get rid of this error ?

Maybe there’s another way to show the category image in the header ?

Thanks,

 
Magento Community Magento Community
Magento Community
Magento Community
 
brax
Jr. Member
 
Total Posts:  17
Joined:  2008-11-06
 

Hi everyone,

i have almost the same problem. Furthermore i want to display the product-image in my header. I defined a new block in my page.xml with the following code:

<block type="core/text_list" name="bild" as="bild" />

In my template/page/2columns-left.phtml i call this block with:

<div class="header-right">
    
<?php echo $this->getChildHtml('bild'); ?>
</div>

Next i created a file named template/catalog/product/view/bild.phtml with this code:

<?php 
    $_product 
$this->getProduct();
?>
    
<img id="image2" src="<?php echo $this->helper('catalog/image')->init($_product, 'image')->directResize(350,280,3); ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />

In addition i have created a file named template/catalog/category/bild.phtml (like leruss - see above) with this code:

<?php if($_imageUrl=$this->getCurrentCategory()->getImageUrl()): ?>
    
<p><img src="<?php echo $_imageUrl ?>" alt="<?php echo $this->htmlEscape($this->getCurrentCategory()->getName()) ?>" width="475" /></p>
<?php endif; ?>

Next i edit the catalog.xml:

In the <catalog_product_view> section i extends the code with:

<reference name="bild">
    <
block type="catalog/product_view" name="product.info.bild" template="catalog/product/view/bild.phtml" />
</
reference>

This works fine. My product-image shows the product-image in the defined block “bild” in the header. But when i try to modify the <catalog_category_default> section, to show the category-image, it displays nothing.

Code: in catalog.xml - <catalog_category_default> section:

<reference name="bild">
    <
block type="catalog/category_view" name="category.bild" template="catalog/category/bild.phtml" />
</
reference>

Maybe i did not understand some basics about the block-thing in magento.

 
Magento Community Magento Community
Magento Community
Magento Community
 
brax
Jr. Member
 
Total Posts:  17
Joined:  2008-11-06
 

Update:

I did this entry in catalog.xml in the section <catalog_category_layered>:

<reference name="bild">
    <
block type="catalog/category_view" name="category.bild" as="test" template="catalog/category/bild.phtml"/>
</
reference>

Now,it work fine for catagory images.

But furthermore, i want to display on every other page (excluded product- and catagory-pages) a default image. Is there anybody outthere, who can help me or has the same problem? Maybe i have to write an own module? Please help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
mrspeaker
Member
 
Total Posts:  44
Joined:  2009-01-19
 

This thread was old, but I thought I’d just add in my “fix” to leruss’ issue:

If you add the

<block type="catalog/category_view" name="category.image" template="catalog/category/cat_img.phtml" />
line in page.xml, then the code dealing with categories will make no sense on the home page (or other non-catalog pages) and so it gives that error message.

By adding it in the catalog.xml file, it will only appear on catalog pages. I added it in

<catalog_category_default>
as:
<reference name="header">
            <
block type="catalog/category_view" name="category.image" template="catalog/category/cat_image.phtml" /> 
        </
reference>

Which worked for my needs.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rybrown18
Jr. Member
 
Total Posts:  29
Joined:  2008-04-08
 

Hello,

I have follwed the instruction listed here and I am not getting an error, but the category image is not appearing in the header, any ideas?
Is anyone still using this code?

 
Magento Community Magento Community
Magento Community
Magento Community
 
rybrown18
Jr. Member
 
Total Posts:  29
Joined:  2008-04-08
 

Hello,
Any help on this woudl be greatly appreciated!!!
Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
studija4d
Jr. Member
 
Avatar
Total Posts:  2
Joined:  2009-09-24
 

Thank you very much, mrspeaker, it works !

http://www.studija4d.lt

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sergio P.
Jr. Member
 
Total Posts:  6
Joined:  2010-04-10
 

Hello everybody. I tried to do this on Magento 1.4, but something gone wrong.
I follow Brax instructions and i get a similar error in home page. But, if i move the piece of code from page.xml to catalog.xml as mrspeaker says, nothing happens.

Any suggestion?

Thanks

Sergio

<EDIT> It works!!! </EDIT>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sergio P.
Jr. Member
 
Total Posts:  6
Joined:  2010-04-10
 
mrspeaker - 27 January 2009 07:12 PM

This thread was old, but I thought I’d just add in my “fix” to leruss’ issue:

If you add the

<block type="catalog/category_view" name="category.image" template="catalog/category/cat_img.phtml" />
line in page.xml, then the code dealing with categories will make no sense on the home page (or other non-catalog pages) and so it gives that error message.

By adding it in the catalog.xml file, it will only appear on catalog pages. I added it in
<catalog_category_default>
as:
<reference name="header">
            <
block type="catalog/category_view" name="category.image" template="catalog/category/cat_image.phtml" /> 
        </
reference>

Which worked for my needs.

...and if I need to have a default image on the HOME PAGE like randomutterings sad in the first post?
Can you help me?

S.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Kangaroos
Jr. Member
 
Total Posts:  18
Joined:  2009-09-30
 

I’ve followed leruss and mrspeaker posts and got the category images showing on the header. My question is how can I have a default image for the homepage and all other non-categogy page? Please help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
istvannonn
Jr. Member
 
Total Posts:  11
Joined:  2010-03-14
Oradea
 

WORKS perfectly.
Thank you for leruss and mrspeaker.

I figured it out putting current category image into product detail page.

Follow leruss’s solution, then mrspeaker‘s solution with the difference that I put

<block type="catalog/category_view" name="category.image" template="catalog/category/cat_img.phtml" />
in catalog.xml under
<catalog_product_view translate="label">

My cat_img.phtml files:

<?php
    $_category  
$this->getCurrentCategory();
    
$_imgHtml   '';
    if (
$_imgUrl $_category->getImageUrl()) {
        $_imgHtml 
'<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p>';
    
}
?>

<?php 
if($_imgUrl): ?>
    <?php 
echo $_imgHtml ?>
<?php 
endif; ?>

All the best and happy coding.

 
Magento Community Magento Community
Magento Community
Magento Community
 
samleaver
Member
 
Total Posts:  45
Joined:  2008-03-04
 

Just spent four hours trying to fix the view.php issue and mrspeaker’s comment pointed me in the right direction - thanks very much!

 
Magento Community Magento Community
Magento Community
Magento Community
 
oe_eduardo
Jr. Member
 
Avatar
Total Posts:  29
Joined:  2011-02-03
London
 

please see the folowing tread with the explanation about how to create a new reference and block to move the categories the cms block to the header....

http://www.magentocommerce.com/boards/viewthread/224094/#

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top