Image widget with rollover and hyperlink
-
Hi all, i’m working on my first plugin and would be grateful of a little help.
I’m trying to create a simple plugin that provides a sidebar widget with a background image that links to a url supplied by the user. I also want the image to change when the user hovers the mouse over the image.
There may be widgets out there like this already, but this is more of a personal learning exercise (although I would be interested in some examples as I do actually have to use this on a live website, so I need something that actually works). I know this is already possible by pasting code into a text widget, but I would like to give the user a simple backend for the link, and later add in other options as my experience grows.
I’ve had limited success with a couple of approaches. 1) I can define the image and the link in my widget php file with the following code – the $name (really the url but I haven’t changed the name yet) and the $image values are strings read in from the widget settings:
echo '<a href=' . $name . '><img src=' . $image . ' /></a>';
The image works as a link but the rollover doesn’t work (the rollover is defined in the css, shown below)
If I only supply the link, and set the background image of the widget in the stylesheet, the rollover works but then there is nothing to fill the link with, meaning there’s nothing to click (the css is the same for both approaches, but only the second has the background rule):
echo '<a href=' . $name . '></a>';
.hyper-image { padding: 0 !important; height: 64px; width: 300px; overflow: hidden; background: url(images/bg_rollover.png); top left no-repeat; display: block; } .hyper-image:hover { background-position: bottom left; }
I’m probably doing something very silly. It’s actually not often that I work with image links and aside from modifying wordpress themes, I don’t know a lot about php.
I would appreciate another insight, thank you.
- The topic ‘Image widget with rollover and hyperlink’ is closed to new replies.