Showing posts with label hacks. Show all posts
Showing posts with label hacks. Show all posts

Wednesday, September 20, 2006

Super Peek-A-Boo Posts

Ramani and I proudly present our Super Peek-A-Boo posts: you can expand them from summary to full post, collapse them, and if you don't have a post summary in a particular post, the "Read More..." and "Collapse" links will not show up in your post.


As you can see in this post, it starts with only the summary, followed by the 'Read more...' link. Clicking the link expands to the full post. Now at the bottom you will find a 'Summary only...' link, that collapses the post back to its summary.

This hack was first implemented by Ramani at Hackosphere. I expanded on it to make it collapsable. Together we developed the finishing touch of hiding the expand/collapse link when there is no need for them.

This is how to implement it.

Step 0:
Back-up your template before modifying it.

Step 1:
Add the following javascript code to the head of your template. You can place it just above the </head>-tag.



<script type='text/javascript' src='http://www.anniyalogam.com/widgets/hackosphere.js' />


Step 2:

Find the includable named 'post' in your template, and change it so that it is exactly as shown below (the code in red has to be added):

<b:includable id='post' var='post'>
<div class='post'>
<a expr:name='data:post.id'/>
<b:if cond='data:post.title'>
<h3 class='post-title'>
<b:if cond='data:post.url'>
<a expr:href='data:post.url'><data:post.title/></a>
<b:else/>
<data:post.title/>
</b:if>
</h3>
</b:if>
<div class='post-header-line-1'/>

<div class='post-body'
 expr:id='"post-" + data:post.id'>
<b:if cond='data:blog.pageType == "item"'>
<p><data:post.body/></p>
<b:else/>
<style>#fullpost {display:none;}</style>
<p><data:post.body/></p>
<span id='showlink'>
<p><a expr:onclick='"javascript:showFull(\"post-" + data:post.id + "\");"' href='javascript:void(0);'>Read More...</a></p>
</span>
<span id='hidelink' style='display:none'>
<p><a expr:onclick='"javascript:hideFull(\"post-" + data:post.id + "\");"' href='javascript:void(0);'>Summary only...</a></p>
</span>
<script type='text/javascript'>checkFull("post-" + "<data:post.id/>")</script>
</b:if>
<div style='clear: both;'/> <!-- clear for photos floats -->
</div>
</div>
.... rest of template code ....


Save your template.

Step 3:
In the Settings - Formatting tab go to the bottom and enter the following post-template:

Type your summary here.
<span id="fullpost">
Type the rest of your post here.
</span>


Now every new post you start will have a fullpost-span by default. If your post is short, you can delete the <span>-tags from the post. The post will be displayed in full, and no links with "Read more..." or "Summary only" will be displayed for that post.

How it works (skip this if you don't like tech stuff).
The changes you made to the code make that every post-body consists of at least 3 span's: the fullpost-span that you entered in the post-template, a span for the 'Read more'-link, and a span for the 'Summary only'-link. Because there might be other spans in your post, each of these 3 spans have a unique id ('fullpost', 'showlink' and 'hidelink' respectively).
When you open your blog on the main page, the post is displayed as follows:


  • Summary is displayed (always)

  • Full text is hidden (first div, set to display:none)

  • Read more is shown (second div)

  • Summary only is hidden (third div, set to display:none)

The post is given a unique id, and this id is passed to the javascript-functions showFull and hideFull respectively. These functions use the getElementsByTagName-methods to obtain handles to the spans, and then toggle the way they are displayed.
A third function, checkFull, checks if the Fullpost-span exists. If not, both links are hidden.

This post has no summary

This is a post without a summary. As you can see, there is no "Read more..." link at the bottom, as it is hidden with the new Super-Peek-a-Boo functionality.

Monday, September 18, 2006

Sunday, September 17, 2006

Hacks and Bugs

The Undefined Object Error is back again - thanks to my collapsable posts hack. If you click on the Older Posts link, you get the screen I showed in this picture.

In my last post I showed you my most recent hack to have expandable/collapsable peekaboo-posts, based on the work of Ramani.

I noticed that the Undefined Object Error that devastated my Blog last week, had returned. Luckily, I had saved my old template, and some uploading of templates proved what I suspected: implementing the hack leads to this horrible screendump.
Check it out for yourself, in 3 steps.

Step 1: download and backup your current template.

Step 2: get my template with peekaboo posts, and upload it to your blog.
Check for yourself how nice it works, and how shocking the screendump is when cliking older posts.

Step 3: get my template with normal posts, and upload it to your blog. The Older Posts link will work fine again.

I checked ou several Blogs, and found this bug on the following blogs:

Collapsable Posts

Ramani at Hackosphere published a great hack on expandable posts, that expand on the Blog main page. Building on this excellent work, I developed this hack to expand and collapse posts.

As you can see in this post, it starts with only the summary, followed by the 'Read more...' link. Clicking the link expands to the full post. Now at the bottom you will find a 'Summary only...' link, that collapses the post back to its summary.

If you want to know how this hack works, first check out the original hack at Hackosphere.
My hack works along exactly the same lines, with some code added.

Step 1:
Add the following javascript functions to the head of your template:

<script type='text/javascript'>
function showFullPost(id) {
post = document.getElementById(id);
var fullpost = post.getElementsByTagName('div');
if (fullpost.length != 0) {
fullpost[0].style.display = 'inline';
fullpost[1].style.display = 'none';
fullpost[2].style.display = 'inline';
}
}
function hideFullPost(id) {
post = document.getElementById(id);
var fullpost = post.getElementsByTagName('div');
if (fullpost.length != 0) {
fullpost[0].style.display = 'none';
fullpost[1].style.display = 'inline';
fullpost[2].style.display = 'none';
}
}
</script>


Step 2:

Find the includable named 'post' in your template, and change it so that it is exactly as shown below (the code in red has to be added):

<b:includable id='post' var='post'>
<div class='post'>
<a expr:name='data:post.id'/>
<b:if cond='data:post.title'>
<h3 class='post-title'>
<b:if cond='data:post.url'>
<a expr:href='data:post.url'><data:post.title/></a>
<b:else/>
<data:post.title/>
</b:if>
</h3>
</b:if>
<div class='post-header-line-1'/>

<div class='post-body'
 expr:id='"post-" + data:post.id'>
<b:if cond='data:blog.pageType == "item"'>
<p><data:post.body/></p>
<b:else/>
<style>#fullpost {display:none;}</style>
<p><data:post.body/></p>
<div>
<p><a expr:onclick='"javascript:showFullPost(\"post-" + data:post.id + "\");"' href='javascript:void(0);'>Read More...</a></p>
</div>
<div style='display:none'>
<p><a expr:onclick='"javascript:hideFullPost(\"post-" + data:post.id + "\");"' href='javascript:void(0);'>Summary only...</a></p>
</div>
</b:if>
<div style='clear: both;'/> <!-- clear for photos floats -->
</div>
</div>
.... rest of template code ....


Save your template.

Step 3:
In the Settings - Formatting tab go to the bottom and enter the following post-template:

Type your summary here.
<div id="fullpost">
Type the rest of your post here.
</div>

How it works (skip this if you don't like tech stuff).
The changes you made to the code make that every post-body consists of 3 div's: the fullpost-div that you entered in the post-template, a div for the 'Read more'-link, and a div for the 'Summary only'-link.
When you open your blog on the main page, the post is displayed as follows:


  • Summary is displayed (always)

  • Full text is hidden (first div, set to display:none)

  • Read more is shown (second div)

  • Summary only is hidden (third div, set to display:none)

The post is given a unique id, and this id is passed to the javascript-functions showFullPost and hideFullPost respectively. These functions use the getElementsByTagName-methods to obtain handles to the 3 divs, and then toggle the way they are displayed.
Once I understood how Ramani had done the trick, it was easy to expand on his work.

Next steps.
It should also be possible to have posts without a summary. I'll try to get that done soon.

Added a Favicon to my Blog

Thanks to Annie's tutorial I added a cute favorite icon to this Blog.

Showing favorite Blogs in new window

An easy to implement hack to let links show up in a new window.

I found this simple hack at Vivek's blog a few days ago.

If you have a 'Links'-widget in your sidebar, clicking a link will show the linked-to webpage or blog in the same window, replacing your blog.

If you add target='_blank' in the widget (see below, in red) the linked-to webpage or blog will open in a new window.

<b:widget id='LinkList1' locked='false' title='Blogs of Note' type='LinkList'>
<b:includable id='main'>
<b:if cond='data:title'><h2><data:title/></h2></b:if>
<div class='widget-content'>
<ul>
<div id='link'>
<b:loop values='data:links' var='link'>
<li><a expr:href='data:link.target' target='_blank'><data:link.name/></a></li>
</b:loop>
</div>
</ul>
<b:include name='quickedit'/>
</div>
</b:includable>
</b:widget>

Saturday, September 16, 2006

RSS-feed online now

You can now get my RSS-feed from my sidebar.

Following Anniebluesky's example, I set up a Feedburner RSS-feed. I added a html-page element to my sidebar, called it 'Syndication' and added the FeedBurner code to it.

To make sure that visitors only use the FeedBurner-link, and not the 'Subscribe to Posts (Atom)' link at the bottom of my posts, I hid this part using css:

.feed-link { display: none }

As an alternative, you could remove the feedlink from your widget, but I prefer the css-solution, in order to stay as close to the Blogger standard widgets as possible.

Friday, September 15, 2006

Showing number of backlinks on footer

This hack shows the number of backlinks in your footer.

This hack is similar to the comments-hack I explained earlier.

Look for the backlinks-part of the posts, and add the red code.

<!-- backlinks -->
<span class='post-backlinks post-comment-link'>
<b:if cond='data:blog.pageType != "item"'>
<b:if cond='data:post.showBacklinks'>
<a class='comment-link' expr:href='data:post.url + "#links"' title='Check out who is linking to this post'>
<b:if cond='data:post.numBacklinks == 1'>1 Backlink
<b:else/>
<b:if cond='data:post.numBacklinks == 0'>
No <data:top.backlinkLabel/>
<b:else/>
<data:post.numBacklinks/> <data:top.backlinkLabel/>
</b:if></b:if>

</a>
</b:if>
</b:if>
</span>

Last Visit Message

Want to give your visitors a warm welcome and show them when they last visited your Blog? This is how it is done!

All experienced Blog-hackers will tell you that those Javascripts will terribly slow down the loading of your Blog.

I know that's true, but still, now and then I like one of those thingies on my Blog.

I added a Last Visit Message, that shows when you visited my blog for the last time.

It is very easy to implement.
First, add a new Page Element of the HTML-type to your Layout. Add the
following javascript code to the contents of this Page Element, and save.
Your message is ready!

If you want this message to appear only at your Blog's main page, you have to edit the widget in your template.
Look for the widget, and add the <b:if>-statements as shown in red:

<b:widget id='HTML1' locked='false' title='Last Visit' type='HTML'>
<b:includable id='main'> 

<!-- only display if on homepage -->
<b:if cond='data:blog.url == data:blog.homepageUrl'>

<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>
<b:include name='quickedit'/> 

</b:if>
</b:includable>
</b:widget>

Wednesday, September 13, 2006

Adding a tooltip to your labels-links

Another polish-and-shine hack: add a tooltip to the labels-links. Hovering your mousepointer over the link in your posts footer will show a tooltip saying "More posts on this topic".

Insert the red code into your template.

<span class='post-labels'>
<b:if cond='data:post.labels'>
<data:postLabelsLabel/>
<b:loop values='data:post.labels' var='label'>
<a expr:href='data:label.url' title='More posts on this topic' rel='tag'><data:label.name/></a><b:if cond='data:label.isLast != "true"'>,</b:if>
</b:loop>
</b:if>
</span>

Easy!

More hacking into the comments line

On second thought: why not adapt the "0 comments" to something more interesting like "No comments at all" or "Please please please leave a comment" ?

It is easy as this. For explanation see my post on the 1 comment workaround.

<b:if cond='data:post.allowComments'>
<a class='comment-link' expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick'>
<b:if cond='data:post.numComments == 1'>1 comment
<b:else/>
<b:if cond='data:post.numComments == 0'>No comments
<b:else/>
<data:post.numComments/> <data:top.commentLabelPlural/>
</b:if>
</b:if>
</a>
</b:if> 

Adding a Message Board to your Blog

As you can see I added a Message Board to my Blog, that sticks to the top of the page. It is not a Post, but a Page Element that can be edited from the Layout Editor.

This is how I implemented the Message Board.

Add a new section to the template

At the top of the content-part, just beneath the content-wrapper div, add a new <div>, with a unique id (I chose 'message-board'). Inside this <div> add a new section, with a unique id and class. Set maxwidgets to 1, and showaddelements to 'yes'.

<div id='content-wrapper'>
<div id='message-board'>
<b:section class='msgbrd' id='msgbrd' maxwidgets='1' showaddelement='yes'/>
</div> 


Add variables to the css-part of your template

To control the font and colors of the Message Board, add the following variables to your css:

<Variable name="MsgBrdFont" description="Message Board Font" type="font" default="italic normal 100% Verdana, Arial, Sans-serif;" value="italic normal 100% Verdana, Arial, Sans-serif;">

<Variable name="bgMsgBrd" description="Messageboard Background Color" type="color" default="#ffffff" value="#ffffcc">
<Variable name="borderMsgBrd" description="Messageboard Border Color"
type="color" default="#336699" value="#336699">
<Variable name="colMsgBrd" description="Messageboard Text Color"
type="color" default="#000000" value="#000000">


Add style-definitions for your Message Board classes

Now add the following css to the template.

/* Messageboard */

.msgbrd h2 {
display: none;
}

.msgbrd .widget-content {
padding: 2px 2% 2px;
background-color: $bgMsgBrd;
border: 4px solid $borderMsgBrd;
color: $colMsgBrd;
font: $MsgBrdFont;
}


Add the MessageBoard content

In the Add Page Elements-part of the Layout Editor you will see the new section just beneath your Header.
Click 'Add a Page Element' here, and select Text.
Enter a title and a message, and click Save.
Voila!

Adding a second sidebar to your template

The Challenge

Now that we have learned about the section, it is fairly easy to add a second sidebar to your template. And what is even better: you can maintain this sidebar from the Blogger Beta Page Element layout screen!

How it works

The Blogger Beta template uses <div>-tags for several "wrappers".
The header is inside the Header-wrapper. The sidebar is inside the Sidebar-wrapper. The main section is inside the Main-wrapper, and the footer is inside the Footer-wrapper.
Main-wrapper and Sidebar-wrapper are inside the Content-wrapper.
And Header, Content, and Footer are surrounded by the Outer Wrapper.

The code looks like this:


<div id='outer-wrapper'>
    <div id='header-wrapper'>
      <b:section id='header' class='header' ....>
   </div>
   <div id='content-wrapper'>
      <div id='main-wrapper'>
         <b:section id='main' class='main' ....>
      </div>
      <div id='sidebar-wrapper'>
         <b:section id='sidebar' class='sidebar' ....>
      </div>
   </div>
   <div id='footer-wrapper'>
      <b:section id='footer' class='footer' ....>
   </div>
</div>

You will easily recognize this structure from your template.

You can add a left-sidebar in 3 easy steps:

Add a new wrapper for the left-sidebar to your template, inside the content-wrapper and in front of the main-wrapper.
Add a new section inside this wrapper, with a unique ID (for example leftsidebar) and set its class to 'sidebar'.

This is the code:

<div id='leftsidebar-wrapper'>
<b:section id='leftsidebar' class='sidebar' preferred='yes'/>
</div>

In the head of your template add css-code for a #leftsidebar-wrapper element, and set it to float left.
Adjust the width of your sidebars and your main-wrapper to fit the screen.

Editing your new sidebar
Now go to the layout-editor, and you will see the new sidebar to the left in your Page Elements Screen, and you can add new page elements to your new sidebar.