Posts Tagged ‘links’

Using CSS to highlight a link

Now you know how to add a really cool hidden link in CSS but what about if you want to make certain links stand out? Just as easy

First, when you add a link to your website we want to assign a class to it like so:

<a href=’http://www.thisismyurl.com’ class=’standout’>

In my case, I’ve labeled this link with the special tag standout which will let me affect the appearance. Next in the CSS, let’s add a special rule for it:

a.standout {
/* this is what we want the normal link to appear as */
text-decoration: none;
font-color: #990000; /* (assuming you want your link blood red */
font-weight: bolder;
}

a.standout:hover {
/* when people mouse over the link */
font-color: #000000; /* (assuming your default text is black) */
cursor: default;
text-decoration: underline;
}

In this example, I’ve made the link red but still taken the underline away. I’ve put the underline back when you mouse over the link which calls extra attention to it and shows the user there’s something interactive with the link.

How’s it work? Pretty simple really, any time your HTML calls an <a> tag with the class standout, the CSS will be loaded and in turn change the appearance of your site to accommodate the new new.

Show both links and pictures in WordPress wp_list_bookmarks()

showingbothlinksandpics 153x300 Show both links and pictures in WordPress wp list bookmarks() imageAs some of you may have noticed, I updated the design for my site this week. It was a pretty major overhaul of the basic code, although it is still 100% WordPress. The upgrade that I’ve had the most messages about is my links list at the bottom of the page. It uses the standard WordPress Links list with a few minor scripting changes.

By default, WordPress wp_list_bookmarks() will display either the graphic or the title of your link but not both. If there is a graphic image set, it will simply ignore the title and output only the graphic. If no graphic is present, it will only output the text. Not exactly what I wanted.

What I wanted was what Jeremy had. So I set about trying to find the code to do this in WordPress only to find out that it simply didn’t exist. What I did find was a lot of people grumbling about it, so  I fixed the problem using WordPress’s built in get_bookmarks() function.

Here’s what I did:

<strong>What I’m Reading</strong>
<ul><?php 

$linklist = get_bookmarks(‘category=70′); 
foreach ($linklist as $site) { 
echo “<li>”;
if (strlen($site->link_image)>2) {
echo “<span class=’linkimage’>”;

echo “<a href=’”.$site->link_url.”‘ title=’”.$site->link_description.”‘ rel=’me’><img src=’”.$site->link_image.”‘ alt=’”.$site->link_name.”‘/></a>”;
echo “</span>”;

} else {
echo “<span class=’linkimage’></span>”;
}

echo “<span class=’linkname’>”;
echo “<a href=’”.$site->link_url.”‘ title=’”.$site->link_name.”‘ rel=’me’>”.$site->link_name.”</a>”;
echo “</span>”;
echo “</li>\n\r”;
}
?></ul>

For those of you who know PHP what I did was pretty simple but for the rest of you, here’s the basic breakdown:

$linklist = get_bookmarks(‘category=70′); 

Get the values of category #70 (I only wanted those links) and load them into a variable.

foreach ($linklist as $site) { … }

Loop through the variable.

if (strlen($site->link_image)>2) { … }  else { … }

If the link_image value (that’s where the image is stored) has a value of more than two characters, do this. Otherwise, do something else. For the record, sometimes the value returned a false positive when testing for isset() so I choose to do a strlen() instead.

echo “<span class=’linkimage’>”;
echo “<a href=’”.$site->link_url.”‘ title=’”.

$site->link_description.”‘ rel=’me’><img src=’”.$site->link_image.”‘ alt=’”.$site->link_name.”‘/></a>”;
echo “</span>”;

The code above displays a <span> tag. I repeat the process if there’s no image found using an empty <span> tag to keep the text alignment appropriate.

echo “<span class=’linkname’>”;
echo “<a href=’”.$site->link_url.”‘ title=’”.$site->link_name.”‘ rel=’me’>”.$site->link_name.”</a>”;
echo “</span>”;
echo “</li>\n\r”;

Finally, I display another <span> called linkname which stored the text based hyperlink to the site. 

That’s all she (actually he) wrote … do you have any suggestions how to improve this code? Let me know and I’ll owe you a pint. Also, if you use this code please post a link to your website below so that I can see it in action. Thanks.

Win an iPod Nano

Thanks all who took part, the contest is now over.

 

Win an 8GB iPod Nano just for linking from your website to thisismyurl.com.

The rules are really simple, write a review of thisismyurl.com and post it on your website with a link back to my site include a link to an article on my site, ideally as a review but it’s up to you. Leave me a comment below with a link to the article on your site so I can check it out.

The Winner will be selected randomly from those who follow the rules and enter. I’ll announce the winner on November 15th and order you a brand new 8GB iPod Nano from Apple before the holidays. Good luck.