Solved

replace category title text with an image in magento 1.7

Posted on 2013-02-03
3
767 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 43

Accepted Solution

by:
Chris Stanyon earned 500 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 43

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Echo vs ?><?php  html code 4 45
change password links 7 72
Mysql sync between 3-4 mysql db 4 24
Set robocopy to exclude "System Volume Information" folder 3 25
A short article about problems I had with the new location API and permissions in Marshmallow
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

911 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

21 Experts available now in Live!

Get 1:1 Help Now