Solved

replace category title text with an image in magento 1.7

Posted on 2013-02-03
3
760 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 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
Comment Utility
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
Comment Utility
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 42

Expert Comment

by:Chris Stanyon
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now