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

Move Category Title to header only on category pages
 
eCom
Member
 
Total Posts:  53
Joined:  2008-04-20
 

Hi,
I must say I looked all over for a solution for this issue, but still I have one bug. Here Goes:

I wanted to move the category name from the canter of the page to its top left area in the header (above the logo).
I was trying to make it using the good magento way: using new phtml and layout xml files.

Created a file in: app/design/fronted/default.<THEME>/catalog.category/cat_name.phtml
this file has the following code that retrieves the current category name, using mage registry

<?php  //add the category name to the header   ?>

<?php if(Mage::registry('current_category')):?>
        <?php
            $_helper    
$this->helper('catalog/output');
            
$_category  $this->getCurrentCategory(); ?>
        
<h1><?php echo $_category->getName() ?> </h1>
<?php endif; ?>
Then I added to the header.phtml
<?php echo $this->getChildHtml('category.name'?>
and finally to page.xml, (just below this:
<block type="page/html_header" name="header" as="header">
)
added this
<block type="catalog/category_view" name="category.name" template="catalog/category/cat_name.phtml" />

The thing is that it worked but not well: it made a blank CMC pages, and it did show in the product pages.
I need it to show ONLY category pages. How can I accomplish this as it seems quite simple but I can’t figure it out.

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
clorne
Sr. Member
 
Total Posts:  236
Joined:  2008-01-10
London
 

Hi

If you haven’t already, try changing

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

to

<block type="catalog/category_view" name="category.name" as="category.name" template="catalog/category/cat_name.phtml" />
 
Magento Community Magento Community
Magento Community
Magento Community
 
eCom
Member
 
Total Posts:  53
Joined:  2008-04-20
 

Hi

If you haven’t already, try changing

<block type="catalog/category_view" name="category.name" template="catalog/category/cat_name.phtml" />
to
<block type="catalog/category_view" name="category.name" as="category.name" template="catalog/category/cat_name.phtml" />

Thanks but the results are the same.
Any other ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
clorne
Sr. Member
 
Total Posts:  236
Joined:  2008-01-10
London
 

One easy but maybe time consuming, depending on the number of categories affected, is to add

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

to

Custom Layout Update

of the relevant categories

 
Magento Community Magento Community
Magento Community
Magento Community
 
eCom
Member
 
Total Posts:  53
Joined:  2008-04-20
 
clorne - 28 March 2011 08:19 AM

to

Custom Layout Update

of the relevant categories

Thanks. - Thought of that, but it really is time consuming and its to all categories.
I’m sure there is a “Magento” way of doing it, something like what i did, but better (and bug free...)

Anyone else?

 
Magento Community Magento Community
Magento Community
Magento Community
 
eCom
Member
 
Total Posts:  53
Joined:  2008-04-20
 

I’m happy to say, that I managed to fix it.
After a bit of drilling, in order to show something in the category pages only, we need to add the block in the default category section of the catalog.xml and not in the page.
This should resolve the blank pages for other pages than the category. I solution was found in a almost similar request, that was answered here by mrspeaker.

I added the following block under the catalog_category_default and to catalog_category_layered sections in the catalog.xml

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

I hope this helped someone!

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

Hi all,

I was some hours trying to move the static block defined at the categories (manage categories -> display settings -> CMS block)

I wanted to have it before the breadcrum but only in the categorie pages that have configure the cms static block

With the help of Tomislav Bilic from inchoo i manage to make it work.

http://inchoo.net/ecommerce/magento/custom-reference-structural-block/

that the steps in case some need it.

1- create your new reference:

I always scare of upercases, hifens and underscores in zend one day i will learn how to use them so i call the reference “categorybanner” and become a reference because the block type is core/text_list (not sure do but works like the other references like left)

template->layout->page.xml

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

2 - Use the reference for the categories.

Because we want to be show only at the categories we open:

template->layout->catalog.xml

there is an error show in other posts when you add the reference to the block at the page.xml because at the home page will try to get the category methods and will fail.

also be sure you add the reference at the sections you want to show the banner for example at the layeared navigation layout:

"<catalog_category_layered translate="label">"

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

I am using the template catalog/category/banner.phtml that uses the methods of catalog/category/view.phtml so in block type you have to put catalog/category_view (you see why i am scearing of underscores)

3 - Now we call the reference from a template

In my case i am using my own call catalog.phtml base in the 2columns-left.phtml
(i wont say how to add your template otherwise i never go to eat my lunch)

If you use your template remember to change the default template at :

template->layout->catalog.xml

<reference name="root">
            <
action method="setTemplate">
                <
template>page/catalog.phtml</template>
            </
action>
        </
reference>

Ok now open what ever template you have for your category and add the cade to call the reference:

As I said wanted before the breadcrumbs so i put that before breadcrumbs like that:

<?php echo $this->getChildHtml('categorybanner'?>

                <?php 
echo $this->getChildHtml('breadcrumbs'?>

4 - Put the code in the banner.phtml

Create a banner.phtml at:

template->catalog->category->banner.phtml

<?php
    $_helper    
$this->helper('catalog/output');
    
$_category  $this->getCurrentCategory();
?>

<?php 
if($this->isMixedMode()): ?>
    <?php 
echo $this->getCmsBlockHtml() ?>
<?php 
endif; ?>

5- Finaly hide your static block from the main content (you dont want to headers in the same page!!!)

template->catalog->category->view.phtml

<?php elseif($this->isMixedMode()): ?>
    <?php 
//EGS to implement in category_header.phtml echo $this->getCmsBlockHtml() ?>
    
<?php echo $this->getProductListHtml() ?>

Voila…

Hope help someone,

Is not to dificult just about 9 cofees....

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