Why don't we put one of those share on facebook links at the end of each Blogger post? It seemed like a simple request. Other people had them so it couldn't be too difficult, right?
Well several google groups, blog posts and google searches later I can confidently say, "It really isn't all that difficult. If you know what you are doing."
In an effort to save you the time and energy I dumped into this one I will try to thoroughly explain what I did to get that nifty little share on facebook icon at the end of each of my blog posts.
I guess I should start by mentioning http://addthis.com/ If you want a quick and easy way to include posts to every conceivable sharing service you can sign up for a free account and their site will make a nifty little button that opens a window and allows the user to select whatever service they want. We just wanted a single simple button for posting to facebook and potentially something that could be expanded to include a few other select services.
The first thing I had to do was learn all about this Blogger widget stuff. Its actually not hard to learn if you've had any code writing experience. There are some great resources in the blogger help pages.
I started this particular Blog with the Minima template by Douglas Bowman. Once I understood the basics of the Blogger widget I opened up the Blog's Layout Tab and then selected "Edit HTML" from the sub-menu. In the Edit template section of the page I checked the "Expand Widget Templates" checkbox.
So here we are staring blankly at a text file that contains all the CSS and other little markup tidbits that form our blog layout. Did I mention you probably want to know a little CSS?
At the end of the CSS section I added a section for my customizations:
/* Customizations
------------------------------------------------ */
div.sharelinks{
float:right;
}
div.sharelinks a{
display:block;
text-decoration:none;
text-indent:-9999px;
height:16px;
width:16px;
margin-right:4px;
}
a.facebookshare{
background-image:url(yoururl.com/facebook.gif);
}
As you can see I defined 3 CSS classes. The first class is the div container for my button. I can use this class to position my button and more importantly it allows me to group all my buttons together should I decide to add more in the future. The next class defines all of the common attributes I would like for my share buttons to have. I'm using images for my buttons which is why I have the text-indent set to -9999px. The third class defines the image I want to use for my facebook button, insert your own image as needed.
So now we have to add the widget code that will display our div and our button. I decided that I wanted my buttons to line up with the first line in the footer of each post. To do this I had to locate:
Now to add my button right below it:
<div class='sharelinks'>
<a class='facebookshare' expr:href='"http://www.facebook.com/share.php?u=" + data:post.url' target='blank'>facebook</a>
</div>
</b:if>
Give props to Dave Tips for the basic idea and code that lead to this version. Dave's version was an all markup no CSS version that helped me understand how these templates work.
The first bit sets a condition that states if there is a post url associated with this section of the blog evaluate as true. The markup contained within that if block is displayed each time it evaluates as true.
So the part that was not obvious to me that I learned from Dave's example is how the expr: tag evaluates on render. Notice that the quotes in the href have to be encoded as " also notice that the +data:post.url is outside the quotes. I'm not sure why this works and it seems counter intuitive to me but have no fear it does work. Perhaps someone can shed some light on this part for me?
We are done. All you have to do now is save your changes and go view your blog. Assuming you used the typical facebook 16x16 px icon, there should be a pretty little facebook button after each and every one of your posts.
Hi there,
ReplyDeleteThank you for posting this, how awesome! Although I have little understanding of coding, I do know how to copy paste LOL. That being said, could you help me just a little?
"At the end of the CSS section I added a section for my customizations:"
When I clicked the box to expand widgets it brought me to a box that had the original text script there ending in body close and html close. I tried copy pasting all your 3 boxes below this and it returned an error.
Is there a more appropriate place to put it, or was I actually supposed to have a complete blank text box? I did not delete all the text script previously there as I did not want to lose all m blogging already started.
Did this give you enough info? Thanks for helping me!
Blessed,
ReplyDeleteI sent you a more detailed email earlier this evening but here is the short version for everyone else.
1) You have to put a valid image address in the first block of code where it says "yoururl.com/facebook.gif"
2)The second block of code in this tutorial represents the place you have to look for in your template with widget templates expanded. You will paste the 3rd block of code immediately following the line in your template that matches the 2nd block.
Thank you!!! Your post helped me alot...
ReplyDeleteHaving an issue seeing the actual content of what I want to share.
ReplyDeleteAll that shows in the pop-up is the blog title. No link, no thumbnail, no content.
I think its got something to do with the meta name settings but I'm at a loss.
The blog in question is http://eyebleaching.blogspot.com/
Thanks!
Pocket,
ReplyDeleteI went to your site and it looks like you are up and running with some other gadget for facebook sharing. All I can think of is that the service that fetches content for the share page on facebook was failing.
Did you create the share button you are using now or find it somewhere else? Please share where you got it so others can benefit form your example.
-C.
Hi,
ReplyDeleteThanks for your help with this! I found the places to insert both blocks of code into the HTML and now the facebook share button appears under my posts (yay!) but also this block of code appears above the navigation bar on my blog:
/* Customizations ------------------------------------------------ */ div.sharelinks{ float:right; } div.sharelinks a{ display:block; text-decoration:none; text-indent:-9999px; height:16px; width:16px; margin-right:4px; } a.facebookshare{ background-image:url(http://www.paulandemilytaylor.blogspot.com/facebook.gif); }
How can I get rid of this/what did I do wrong?
Thanks for any help!
Paul & Emily,
ReplyDeleteI took a look at your blog and am happy to say its an easy fix. You placed that style just outside the end of the style block. </style>
Move that block of css just before --></style> in your template and everything will work perfectly.
-C.
Paul & Emily,
ReplyDeleteI also just noticed that your address for the facebook icon does not appear to be valid. If you upload an icon to blogger it got sent to picasa for hosting. yourblog/facebook.gif probably will not work and since my style sends the text -9999px off the screen I don't want you to get confused. What I did was uploaded the icon I wanted to picasa then copied the share url out of there. If you are happy with just the text link you can delete that style block all together.
-C.
Thanks for taking a look at my problem! You were right, I moved the first block of code inside the style block and it no longer shows up at the top of my navbar. However, the facebook share link below my posts also disappeared! Aack!
ReplyDeleteAlso, I just uploaded a facebook icon to Picasa... where do I find the share url? I know these are probably dumb questions, sorry!
ReplyDeleteThese are all good questions that will help others who come after you.
ReplyDeleteYou can get a link to any photo in a picasa web album by clicking on the photo. Then click the link on the right side that says "Link to this photo" the first box that appears, labeled "Link", will have the hosted address of your photo in it. Use that address in the:
"url('http://yourpicasalink')" section of my example and you should be good to go.
Notice im my example my icon is 16 X 16 if yours is bigger or of different dimensions set the height:16px; and width:16px; to the dimensions of your icon.
-C.
OK, I got the icon url figured out, but when I moved the first block of code inside the style block the icon also disappeared from under my posts. Am I putting it in the wrong place? I read somewhere online that new blogger blogs don't use /style to encompass the CSS anymore; instead they use /b:skin so that is what I put the code block inside of. /b:skin encloses codes for Header, Footer, Posts, Widgets, etc. so I assumed that was the CSS section. Is this wrong?
ReplyDeleteThanks again for all your help!