[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

replace category title text with an image in magento 1.7

Posted on 2013-02-03
3
Medium Priority
?
810 Views
Last Modified: 2016-03-02
I have a store run by magento v1.7, it has a custom theme which works flawlessly apart from the fact that I can't get the title text to be replaced by an image.

If possible it would be great if an image could be displayed with the title text over the top for seo purposes.

I have tried several scripts and the image has been uploaded correctly to the media/catalog/category folder, also shows in the backend fine.

This is the script in the view.phtml;

<?php
    $_helper = $this->helper('catalog/output');
    $_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>';
        $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
    }
?>


Any assistance would be greatly appreciated. I am new to magento so please explain clearly. Thanks.
0
Comment
Question by:Dan_Lapodo
  • 2
3 Comments
 
LVL 45

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 38850849
The code you've posted generates the HTML for the image and stores it in the $_imgHtml variable, but it doesn't output it anywhere. You need to make sure you're echoing that variable out wherever in your page you want the image to display. Something like this:

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

Open in new window

0
 

Author Comment

by:Dan_Lapodo
ID: 38851067
Thanks for that ChrisStanyon, it works well and loads the image.

Is there any chance you know how to make the image responsive, the magento theme we have is responsive and when resized the image doesn't degrade?
0
 
LVL 45

Expert Comment

by:Chris Stanyon
ID: 38851207
There're several ways of using images in responsive design, but unfortunately no 'official' way of doing it. They all seem to have their own pros and cons - some rely on extra HTML markup, some just on CSS, and some use Javascript. One solution may be preferred over another but that will be down to your own personal choice / ability / restrictions etc.

I would advise Googling it (responsive design images). There's a lot of good articles out there which discuss the various methods, and you'll likely find one that suits your particular project.

Don't get too hung up on the fact that it's Magento - simply concentrate on the HTML, CSS etc.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Introduction to Processes
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question