Hiển thị các bài đăng có nhãn Tutorials. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Tutorials. Hiển thị tất cả bài đăng

Thứ Sáu, 24 tháng 10, 2008

How To Modify the Blogger Template - The Core Javacript Library for JSON Widgets

This post explains how to make modifications to your New Blogger template, and also houses the latest Javascript JSON library code. This will make it easier for my others articles (and ultimately my readers) as those articles will be referring to this post on how to open the template and add new code.


I. Installing Steps

A. Accessing the "Template" tab

1. If you're from your blog, and you're logged in, click on "Customize"



2. If you're from one blog, and you want to alter the template of another blog, click on "Dashboard"



3. If you're already on "Dashboard", click on "Layout"



4. if you're already inside the Setting page, click on the "Template" tab



B. Change to "Edit HTML" page

To see the template, click on Edit HTML. By default, the template does not expose the internal structure of each widget, so what you see actually is the short form of it. This is indeed a great thing, since you can see quickly how the template is made up from, in textual form. You could also insert the complete widget code of my hack (as instructed in the referred tutorials) right from this collapsed mode.



1) Before you make any serious modifications, it's best to save a copy to your hard drive.

2) Later on, you could always upload a good template up, overriding the current template.

3) This is the toggle that switches between "collapsed" and "explanded widget templates" modes.

4) To insert a new widget, enter the code inside the pair of "b:section" tags with id='sidebar', anywhere in between any two singly "b:widget" lines. Later on, once the code is accepted, it's very easy to visually drag the widget from one place to another, in "Page Element" view.

C. To add CSS or JavaScript code:

1) The preferred place to add CSS code is right in front of the closing b:skin tag

2) The preferred place to add JavaScript code is right between the closing b:skin tag and the closing head tag.



Also, if the hack is labeled as a "JSON Hack", make sure your feed setting is either "short" or "full", but not "None". Let me elaborate on this one:

a. Make sure your feed settings look like this:



b. and not like this:



Also, make sure in "Settings"->"Archiving", "Enable Post Pages?" is set to "Yes"




II. Installing the core Javacript library object

This is the only location where the Core Library will be posted. The reason I do this instead of making a link line to an external js file is because I don't want my users to have a bad feeling of not sure what's going on with the js. I want you to be in control on when you decide to update your existing library version with this latest code.

You only need to place the code below once in your template, as the code is going to be shared among the calling widgets such as TabView, Unlimited Posts, and Unlimited Comments.

Cut and paste the code and paste it between the closing </b:skin> tag and the closing </head> tag :


<script type='text/javascript'>
// Developed by Hoctro - All rights reserved 2007
// This credit must be included in all your derived usages.

// "cb" is intended to be a common library, where different widgets would
// utitlize the shared operations such as getTitle, getLink, etc. from a json object.
var cb = {

// search function requires these parameters:
// 1. query: a blogger address, such as "hoctro.blogspot.com",
// 2. type: type of return data, either "comments" or "posts",
// 3. start: the start-index parameter (where to start extracting data)
// 4. increment: the number of elements the json will get back. (the smaller value, the faster time to travel back)
// 5. func: the returned function the json object will feed.

search: function(query, type, start, increment, func) {
var script = document.createElement('script');
script.setAttribute('src', 'http://' + query + '/feeds/' + type + '/default?alt=json-in-script&amp;start-index='
+ start + '&amp;max-results=' + increment + '&amp;callback=' + func + '&amp;orderby=published');
script.setAttribute('type', 'text/javascript');
document.documentElement.firstChild.appendChild(script);
},

// searchLabel function return a result of posts w/ a label query
// it requires these parameters:
// 1. query: a blogger address, such as "hoctro.blogspot.com",
// 2. an array of labels
// 3. func: the returned function the json object will feed.
searchLabel: function(query, label, func) {
var script = document.createElement('script');
script.setAttribute('src', 'http://' + query + '/feeds/posts/default/-/' + encodeURIComponent(label) +
'?alt=json-in-script&amp;callback=' + func + '&amp;orderby=published');
script.setAttribute('type', 'text/javascript');
document.documentElement.firstChild.appendChild(script);
},

// getTotalResults needs the json object, and it'll return the total number of comments (or posts) of the blog.
getTotalResults: function(json) {
return json.feed.openSearch$totalResults.$t;
},

// getStartIndex gets the start index of a search inside an json object.
getStartIndex: function(json) {
return json.feed.openSearch$startIndex.$t;
},

// getLink return a href link if "name" matches the content inside "a" tags) of the link
getLink: function(entry, name) {
var alturl;

for (var k = 0; k &lt; entry.link.length; k++) {
if (entry.link[k].rel == name)
alturl = entry.link[k].href;
}
return alturl;
},

// getTitle gets the title of the title of an entry of a json object.
getTitle: function(entry) {
return entry.title.$t;
},

// getContent gets the content inside an entry of a json object.
getContent: function(entry) {
return entry.content.$t;
},

// getCommentAuthor: gets the commenter name inside an entry of a json object.
getCommentAuthor: function(entry) {
return entry.author[0].name.$t;
},

// Given a json label search, this function return the decoded label.
getLabelFromURL: function(json) {
for (var l = 0; l &lt; json.feed.link.length; l++) {
if (json.feed.link[l].rel == 'alternate') {
var raw = json.feed.link[l].href;
// The next two lines are borrowed from Ramani's Neo Template
// code. Thanks Ramani!
var label = raw.substr(raw.lastIndexOf('/')+1);
return decodeURIComponent(label);
}
}
},
txt : function (s) {
return s + " Widget by &lt;a href='http://hoctro.blogspot.com" + "'&gt;Hoctro&lt;/a&gt;";
}
};
</script>

Thank you for reading.


Thứ Năm, 23 tháng 10, 2008

Make HTML Text Flashing!

You can do it with some JavaScript magic...


<script type="text/javascript">

<!--

var b_timer = null; // blink timer

var b_on = true; // blink state

var blnkrs = null; // array of spans

function blink() {

var tmp = document.getElementsByTagName("span");

if (tmp) {

blnkrs = new Array();

var b_count = 0;

for (var i = 0; i < tmp.length; ++i) {

if (tmp
.className == "blink") {

blnkrs[b_count] = tmp[i];

++b_count;

}

}

// time in m.secs between blinks

// 500 = 1/2 second

blinkTimer(500);

}

}

function blinkTimer(ival) {

if (b_timer) {

window.clearTimeout(b_timer);

b_timer = null;

}

blinkIt();

b_timer = window.setTimeout('blinkTimer(' + ival + ')', ival);

}

function blinkIt() {

for (var i = 0; i < blnkrs.length; ++i) {

if (b_on == true) {

blnkrs[i].style.visibility = "hidden";

}

else {

blnkrs[i].style.visibility = "visible";

}

}

b_on =!b_on;

}

//-->

</script>





A tad of CSS, e.g.,...
<style type="text/css">

.blink {

font-size: 15px;

color: red;

display: inline;

}

</style>


And a bit of mark-up... ...

<body onload="blink();">

...

This is a test of the <span class="blink">blinking text</span> thingy...which <span class="blink">blinks</span> (in theory)...

...




[i]But just a warning, most people don't like alot of blinking stuff, so you probably should not over-use the effect.


Thứ Tư, 22 tháng 10, 2008

Move Blogger Inline Ads Between Posts to Inside Within Post Position

The new Blogger widget based template that built on XML specification has a feature to add Google AdSense ad unit inline between posts. These inline ads appear between 2 blog posts on homepage, archive and category or label pages, or after the blog content when the single post is viewed individually. :) However, the placement is kind of awkward and low performing in term of click through rate (CTR).



A lot of bloggers have put Google AdSense ad code inside the post or wrap the ad unit around blog post by editing template’s HTML to insert modified ad code manually. Some users may feel uneasy on modifying the AdSense ad code as it may violates AdSense TOS. Anyway, there is another workaround to put AdSense ads in Blogger posts, by using trick to move or duplicate built-in inline ads between posts block to inside the post section. :)



  1. To use the trick to move around AdSense ad unit added by Ads Between Posts, enable and configure inline ads in Blogger using this guide. Note that you must login to your AdSense account from Blogger to establish access authentication. If you don’t have AdSense account yet, you can click on Sing Up button to register for one.

  2. To display this ad within blog post also, click on Template tab, and then click on Edit HTML sub-tab link to open Blogger HTML code template editor to edit the contents of your template.

    Blogger Edit HTML

  3. Backup a copy of your template by click on Download Full Template link, in case it’s is needed be uploaded to Blogger server to recover the template in the event of mistake or corruption.

    Blogger Download Full Template

  4. Click to tick the Expand Widget Templates checkbox.

    Blogger Expand Widget Templates

  5. Find the line with the following text:<data:post.body/>And paste the following block of text before (for ad position before content) or after (for ad position after content) the line above:

    <b:if cond='data:post.includeAd'>

    <data:adEnd/>

    <data:adCode/>

    <data:adStart/>

    </b:if>

  6. Note that maximum of 3 AdSense for Contents (non Link Unit type) ads are allowed on each page.

  7. If you want the AdSense ads inside blog post to appear only when individual blog post is visited, and not on homepage, category or archive pages, wrap the following lines to before and after code added above<b:if cond='data:blog.pageType == "item"'>

    </b:if>
    The whole block added will look like below:

    <b:if cond='data:blog.pageType == "item"'>

    <b:if cond='data:post.includeAd'>

    <data:adEnd/>

    <data:adCode/>

    <data:adStart/>

    </b:if>

    </b:if>


  8. After enabling Show Ads Between Posts in step 1, you will notice that AdSense ads will be shown between posts on all multiple blog posts page, and also after the article on individual single post view. If you don’t want these ads to appear, i.e. to move built-in inline ads to within post, the locate the following block of text which is same with the one we added above:

    <b:if cond='data:post.includeAd'>

    <data:adEnd/>

    <data:adCode/>

    <data:adStart/>

    </b:if>

    And delete these code from template. Note that we have just added a same block of code from step above, so do not remove the newly added code, but the existing code in the template.If you still want the AdSense ad unit to appear between posts when visitors view your blog homepage, label or category pages or archive pages, wrap the code above on top and bottom with the following 2 lines:<b:if cond='data:blog.pageType != "item"'>

    </b:if>
    so that it looks like the following:




    <b:if cond='data:blog.pageType != "item"'>

    <b:if cond='data:post.includeAd'>

    <data:adEnd/>

    <data:adCode/>

    <data:adStart/>

    </b:if>

    </b:if>


    Note that the two lines should be added to the existing block of code in template, not the block which we added in step above.


  9. Click on SAVE TEMPLATE button to save the new hacked template. Now the ad should be appear inside blog post without actually modify ad code. You can also use the same hack theory above to place the ads on different location.

Drop Down Menu Widget For Blogger

Blogger Beta provides an easy way to create link lists even for those who don’t know HTML. But, there is no such functionality for drop-down menus. I found an interface, similar to that of Beta, with which you can easily create drop-down menus and add them to your blog with one-click! ;)


Just goto Drop-down menu creator page and add your menu items one by one by providing a name and URL for each item. :) The updated menu will be shown to you. Once you created the menu , Click the button to add it to your blog. You will see a page , where you can select the blog (if you have more than one), provide a title for your menu and then click “Add Widget“. You will see the widget getting added to your sidebar which you can move around to wherever you want. All this can be done without touching the template code!

Hacking Technique: Feeds on Front Page Only

It seems to me that the Blogger Beta team fixed the problems with comment feeds already. I tested it and it works fine. I noticed something really cool and logical too. Instead of using the blog ID (do you know off the top of your hat your site ID? I don't,) they utilize your homepage address now. So, for now my feeds are, in case anyone cares to know:


  • posts: http://hoctro.blogspot.com/feeds/posts/full

  • Comments: http://hoctro.blogspot.com/feeds/comments/full




Now, here's how I let these feeds shown (by using 2 feed widgets) on my front page only, and not my label/archived/item pages. A very simple but useful trick is employed: put an "if" check to see if the current page is the homepage or not, if so then proceed, otherwise nothing got shown.

Add two lines right inside the main includable:

* Right after the line: <b:includable id='main'>
add this line: <b:if cond='data:blog.url == data:blog.homepageUrl'>
* Right before the line: </b:includable>
add this line: </b:if>

Here is the example I put on the posts feed:


<b:widget id='Feed1' locked='false' title='Latest Posts' type='Feed'>
<b:includable id='main'>
  <b:if cond='data:blog.url == data:blog.homepageUrl'>
    <h2><data:title/></h2>
    <div class='widget-content'>
    <ul id='feedItemListDisplay'>
      <b:loop values='data:feedData.items' var='i'>
        <li>
          <span class='item-title'>
            <a expr:href='data:i.alternate.href'>
              <data:i.title/>
            </a>
          </span>
          <b:if cond='data:showItemDate'>
            <b:if cond='data:i.str_published != ""'>
              <span class='item-date'>
                 - <data:i.str_published/>
              </span>
            </b:if>
          </b:if>
          <b:if cond='data:showItemAuthor'>
            <b:if cond='data:i.author != ""'>
              <span class='item-author'>
                 - <data:i.author/>
              </span>
            </b:if>
          </b:if>
        </li>
      </b:loop>
    </ul>
    <b:include name='quickedit'/>
    </div>
    </b:if>
  </b:includable>
</b:widget>


For that purpose, any widget you want to show only on the front page you can use this trick.

Have a nice day,

Hoctro (9/2006)
Blog: http://hoctro.blogspot.com/




PS: While we're on the subject, if we don't want to see something in the front page, then just change the equal (==) check to become NOT equal (!=),

<b:if cond='data:blog.url != data:blog.homepageUrl'>




Editing your Blogger Template: Adding Editing Pencil to Your Post

While spending time cleaning up my grammar mistakes for my latest post today, I had to stroll to the end of my 6-pages long article again and again, and again (you get the idea :-) to look for the pencil icon to edit the post. Then I thought, hey, why can't I have another pencil at the top of the page, thus saving at least half of my editing time from scrolling down?



After some hacking attempts, the result is sweet:



And so here it is, a hack on "How to add an editing pencil at the top of your post."

Instructions:

Go to your template's HTML editing page, expand it, and look for this line:

<b:include data='post' name='post'/>


add this line right in front of it:

<b:include data='post' name='postQuickEdit'/>

If you use Mr. Ramani's hack (and my enhanced hack to his,) there are two instances of the include (function calls in us hacker jargon :-) so you will have to paste twice in front of each (see picture.)



As you can see, the line just added serves no more than a call to the postQuickEdit function, which in turn will do the checking if you use the editing feature while seeing it live. By putting it in front, you make sure every post on your main page and/or your item page has the pencil. The category/index page in Mr. Ramani's hack is excluded, for we didn't add it in front of the line that prints the title.

That's all folks! Have a nice weekend to you all! Happy (Blogger Beta) Hacking!!!

Hoctro (9/2006)
Blog: http://hoctro.blogspot.com/


To Show or not to Show your template message

Phoenix, one of my readers, noticed that there is some sort of a message bar showing, whenever he clicks on one of the "Label" search. I noticed that too, and knowing Beta code, I thought they must have embedded this new piece of code somewhere on the Blog1 widget. 





Indeed it does, and this new feature only happens to blogs that are created recently. I think this is some sort of a "wrapped-up" feature as part of their "Blogger Beta: Feature Complete!".

Here it is, the single function call which causes the message to display:



So you see, the line is inside the Blog1 widget, under the "main" includable. Turning it off is quite simple if you want to. You can either erase the line or put a pair of comment code like so:

<!-- <b:include data='top' name='status-message'/> -->

and the message will disappear from then on.


Remove (not hide) NavBar with only one small tip


p>NavBar (Navigation Bar) is a horizontal Bar on the top of your template, that has been created by blogger.com. It contents some blog options as: User login, Next and Previous blogs, Dashboard menu..etc... As my opinion, this bar can slow your loading speed, and makes your site looks unprofessional. Therefore, it's unnecessary to keep the Navbar on the top of your hompage, isn't it? You can use this simple tip to remove that annoying Bar completely.p




<
p>You can find some ways online to help you hide the NavBar on your blog by using the CSS code. Keep in your mind that they can only help you hiding the NavBar, not to remove it. Despite the NB is not showing on the top of your page, it is still loaded by browser. This simple tip can help you to remove the NavBar completely and makes your blog loading faster.p>

<
span class="fullpost">

<
p>Here's the instruction:p>

<
p>Open your HTML Edit pages, copy and paste this red code right above the <b>&lt;BODY&gt;b> tag, it looks like:

p><blockquote>

<p class="style1">&lt;!--p>

<
p class="style1">&lt;BODY&gt;p>

<
p class="style1">--&gt;p>

<
p>&lt;BODY&gt;p>

blockquote>

<
p>Click Save Template. Blogger will prompt you to answer "agree" or "not to remove" the NavBar. Click Confirm And Save and ...you're done! Cool isn't it?p>

<
p align="center"><img src="http://anhvo.info.googlepages.com/2008-06-06-05-00-48.png">p>

<
p class="copyright" align="right"><b>Anhvob>

Showing a Hint on Where to Post a Comment

Nanny22girls from Google Help Groups: Customizing Templates
asks if she could reword the comment line at the end of each post in index pages to say "Leave a comment here", along with the number of comments.

After looking into it, here is my quick fix:



In Template->Edit Html, check on "Expand Widget Templates" to view the entire template. Then, locate <b:includable id='post' var='post'>, and keep scrolling down to see this:

<span class='post-comment-link'>
        <b:if cond='data:blog.pageType != "item"'>

          <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 
          <data:top.commentLabel/><b:else/><data:post.numComments/> 
          <data:top.commentLabelPlural/></b:if></a>
          </b:if>
        </b:if>

      </span> 

You are going to replace the code in bold with this code:

<b:if cond='data:post.allowComments'>
  <b:if cond='data:post.numComments == 1'>1 
Comment<!--<data:top.commentLabel/>-->
  <b:else/><data:post.numComments/> 
<data:top.commentLabelPlural/>
  </b:if>
  <a class='comment-link' expr:href='data:post.addCommentUrl' 
expr:onclick='data:post.addCommentOnclick'>Leave your comment here</a>
</b:if>

Notice there is a space at the end of "1" before the code goes to the next line, and the same thing happens with the <data:post.numComments/>. If you don't leave a space, then there won't be a space between the number and the word comment (or comments.) Notice I fix the "1 Comments" bug too.

Here is the result:



and the "1 comments" bug:




Showing Hint under the Title to View a Page With Comments

My friend Carlos asks me how to let readers to see posts with comments. I think this is not possible while a viewer is seeing a label or archived query, or if he or she is looking at the home page. I guess the technical reason why Blogger in Beta didn't implement that, is just simply try to avoid a potentially large stream of data to arrive to the viewer's PC. Imagine a situation where you query a category that has 20 posts in each, each post with 20-30 comments. It'll take quite a while to display that page to your screen.

My work-around to this would be to give a hint to the reader to click on the title of the post in order for him or her to read both the full post and the comments.



If you like this solution, then follow these simple steps:

1. Locate the Blog1 widget

<b:widget id='Blog1' locked='false' title='Blog Posts' type='Blog'>



then the includable named "post"

<b:includable id='post' var='post'>


2. Insert the seven lines in bold to the code. What this does is to check if you're allowing comment for a post, your post has at least one comment ( !=0 ), and you are not on the full post (item) page, then insert the hint. Feel free to use your HTML expertise to alter the simple tags I have, or change the text to become clearer.


<b:includable id='post' var='post'>
  <div class='post uncustomized-post-template'>
    <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 cond='data:post.allowComments'>
        <b:if cond='data:post.numComments != 0'>
          <b:if cond='data:blog.pageType != "item"'>
            <div><i>(For full text with comments please click on the title)</i></div>
          </b:if>
        </b:if>
      </b:if>

    </b:if>


I apply this fix to my webpage, so you can see how this works.

Have a wonderful day,

Hoctro


Hacking Technique: On JavaScript

It was only last week that I was introduced to Hackosphere from Buzz. Ramani showed me a new hacking utopia where one can hack Blogger 3.0 to his or her heart's content. He explained every single one of his hacks to us, in great details, yet still somewhat kept a "secret" (at least for me under my tired eyes from hacking Beta for a week now that I couldn't see straight ;-) - that a week later, after much soul (and google) searching, I found it not too far away but in his treasure chest, once again - the missing piece that glued everything together: how to program Beta with JavaScript. Yes, he kept his "secret" under a link, but once I found out, I can see a truly new world of hacking possibilities.





You see, Blogger Beta provides a way to retrieve a piece of data or a collection of data, along with a (mysterious at first) function-definition and function-call system, the primitive if-then-else expression and the irreplaceable loop command. But, with only those few limited tools, one can only hack so much. What we need is a complete language with variables, array, other kind of loops and logic expressions, to name a few. I guess I kind of know all along that JavaScript is the One, but how to do it in Beta's template is a different matter.

The code Ramani presented us opened up all sorts of interesting things. He showed that we can compare an integer to another, how to declare a variable then assign a Beta piece of data to it, and how to append those data to show in an id using the innerHTML method. It's not that I have not done similar things like that before, it's just that I thought that if Beta is so XML-compliant (it needs the "CDATA" to wrap around CSS instructions, for example ), maybe coding JavaScript the regular way wouldn't work.

Well, his hack works, and so does his JavaScript embedding style.

Based on his success, I was able to write a live demonstration showing the seven different ways to display your homepage by just clicking on a different icon.



Below is the stripped down version of it, showing how to code a printer-friendly vesion on a webpage.

Installation:

To install this hack, follow all the steps from my previous hack. Then, create a fake HTML element. Once this is done, drag it to the bottom bar. Then look for the code near the end of the expanded version of the template. Replace the HTMLX widget with the code below, making sure to fix the id so it would match the id of the template.


<!-- Printer Friendly Hack  9/14/06  - Need to install Yahoo! Grid CSS hack first from here:
http://hoctro.blogspot.com/2006/09/tweaking-new-blogger-yahoo-ui-librarys.html
-->
<b:widget id='HTML3' locked='false' title='' type='HTML'>
<b:includable id='main'>
  <div class='printer-friendly'>
    <a href='javascript:void' onclick='javascript:changeStyle("yui-t6");' title='yui-t7'>Back to normal</a> ***
    <a href='javascript:void' onclick='javascript:changeStyle("yui-t7");' title='yui-t7'>Printer friendly version</a>
   </div>   
  <script language='javascript' type='text/javascript'>
  function changeStyle(style) {
    obj = document.getElementById('doc');
    if (typeof style == "string") obj.className = style;
    }
  </script>

  <b:include name='quickedit'/>
</b:includable>
</b:widget>



That's it! Noticed how JavaScript code can live together with Beta code is such a peaceful and natural manner.

This picture shows the links are placed at an unintrusive location (the very bottom of the page) in normal style,


and in printer frienly version,



This hack shows that if not for anything else, the ability to have a printer-friendly version should worth your time installing my previous CSS Grid hack.

I would like to thank Ramani again for his unselfishness in showing his "secrets" to others, so that we could all push the new Blogger Beta to new heights.

Cheers,

Hoctro (9/14/2006)
Blog: http://hoctro.blogspot.com/





Update: (October 12, 06)
Here is the code I use for showing the hack on my front page. Feel free to use it on your site if you like it.


<b:widget id='HTML2' locked='false' title='Try this h a c k out' type='HTML'>
<b:includable id='main'>
  <!-- only display title if it's non-empty -->
  <b:if cond='data:title != ""'>
    <h2 class='title'><data:title/></h2>
  </b:if>

  <a href='javascript:void' onclick='javascript:changeStyle("yui-t1");' title='yui-t1'>
  <img class='img_cls' src='http://photos1.blogger.com/blogger2/3768/593528219081732/400/t1.jpg'/></a>
  <a href='javascript:void' onclick='javascript:changeStyle("yui-t2");' title='yui-t2'>
  <img class='img_cls' src='http://photos1.blogger.com/blogger2/3768/593528219081732/400/t2.jpg'/></a>
  <a href='javascript:void' onclick='javascript:changeStyle("yui-t3");' title='yui-t3'>
  <img class='img_cls' src='http://photos1.blogger.com/blogger2/3768/593528219081732/400/t3.jpg'/></a>
  <a href='javascript:void' onclick='javascript:changeStyle("yui-t4");' title='yui-t4'>
  <img class='img_cls' src='http://photos1.blogger.com/blogger2/3768/593528219081732/400/t4.jpg'/></a>
  <a href='javascript:void' onclick='javascript:changeStyle("yui-t5");' title='yui-t5'>
  <img class='img_cls' src='http://photos1.blogger.com/blogger2/3768/593528219081732/400/t5.jpg'/></a>
  <a href='javascript:void' onclick='javascript:changeStyle("yui-t6");' title='yui-t6'>
  <img class='img_cls' src='http://photos1.blogger.com/blogger2/3768/593528219081732/400/t6.jpg'/></a>
  <a href='javascript:void' onclick='javascript:changeStyle("yui-t7");' title='yui-t7'>
  <img class='img_cls' src='http://photos1.blogger.com/blogger2/3768/593528219081732/400/t7.jpg'/></a>            

  <script language='javascript' type='text/javascript'>
  function changeStyle(style) {
    obj = document.getElementById('doc');
    if (typeof style == "string") obj.className = style;
    }
  </script>
  <b:include name='quickedit'/>
</b:includable>
</b:widget>


How to add a new CSS parameter to your Blogger template

Cecilia left a comment asking me if I know anything about changing the default background of the blog. As usual, I go looking for answers in several of my CSS books (Bulletproof Web Design, CSS CookBook, Eric Meyer on CSS, etc.) For this one, the answer is right on Chapter 1 of the "Bulletproof Web Design" book. So here it is, if you have one of the Minima designs, please alter the equivalent tags of the template's CSS portion like this:




body {
/*background:$bgcolor;*/
margin:0;
color:$textcolor;
font:x-small Georgia Serif;
font-size/* */:/**/small;
font-size: /**/small;
text-align: center;
background: $bgcolor url(http://photos1.blogger.com/blogger2/7873/821550570340913/1600/bg.gif) repeat-x top left;
}


/* Header
-----------------------------------------------
*/

#header-wrapper {
width:660px;
margin:0 auto 10px;
border-bottom:1px solid $bordercolor;
}

#header {
margin: 5px;
/*border: 1px solid $bordercolor;*/ text-align: center;
color:$pagetitlecolor;
}


/* Outer-Wrapper
----------------------------------------------- */
#outer-wrapper {
width: 660px;
margin:0 auto;
padding:10px;
text-align:left;
border: 1px solid $bordercolor;
font: $bodyfont;
background: #fff;
}



Discussion:

* In CSS, if you want some effects to be temporary disabled, use this /* xxxxxx */ format. Notice that a comment inside another comment is not acceptable, such as

/* xxx /* xxxxxx */ xxx */


*This line, in particular, adds a faded yellow picture to the top-left of the screen, and repeats that picture in the horizontal (x) direction.

background: $bgcolor url(http://photos1.blogger.com/blogger2/7873/821550570340913/1600/bg.gif) repeat-x top left;


* In addition, I tweak some code so that instead of the default two boxes around my title, now I only have a line at the bottom. Since the line is added with same color as the border's, I can change it visually with the "Font and Color" Editing option.

#header-wrapper {
width:660px;
margin:0 auto 10px;
border-bottom:1px solid $bordercolor;
}




* You can add more font and color variables to the template, and they will show up in the "Font and Color" design tab. What this means is that you will have many more options to play around with, not just the default ones from Blogger templates.

For example, I could create a new color variable (inside the <b:skin> tag at the front of the template):

<Variable name="commenttextcolor" description="Comment Text Color"
type="color" default="#999" value="#999999">


and it would show up in the "Font and Color" tab,



This new variable has a name so you can add later as $commenttextcolor in the actual CSS code, a description name for it to show up in "Font and Color" design tab, the type of "color", and a default and actual value. I think Blogger will write whatever your choice back to this "value" so your template is always up-to-date and independent of Blogger's database.

Now that you have a variable, you can apply that to the CSS code, just like any other default variables.

* For my Vietnamese blog, I have used the same code showing in this article to modify its appearance. Please take a look.

Show Adsense in Middle of Posts

Do you notice Adsense ads appearing exactly in the middle of Posts in my Blog? Yes? Now you will also eager to know, how to implement these Adsense ads in middle of your blogger posts, Right?
Ok guys! Today I will show you how to implement content around Adsense ads or implement adsense in the middle of posts in Blogger.First you should know the advantages of this hack.
*More clicks will be generated *It will increase your CTR rate *Your earnings will increase



Ok guys! Today I will show you how to implement content around Adsense ads or implement adsense in the middle of posts in Blogger.First you should know the advantages of this hack.
*More clicks will be generated *It will increase your CTR rate *Your earnings will increase

Any how, it is very easy to implement this hack in your blogger template.You have to follow just few easy steps.So, don't wait and follow the below steps to boost your Adsense earnings!

Note that the below hack work only in Beta Blogger.If you wanna it in Classic blogger, then contact me.

Just Follow the Below Steps for this hack:

First you have to login into your Blogger account & Go to Layout>>Edit HTML.
Now check the "Expand Widget Templates" box.Now search for this <data:post.body/> tag in template.

Now replace the above code (Tag) with the code given below:

<div expr:id='"aim1" + data:post.id'></div>

<div style="clear:both; margin:10px 0">

<!-- Your AdSense code here -->

</div>

<div expr:id='"aim2" + data:post.id'>

<data:post.body/>

</div>

<script type="text/javascript">
var obj0=document.getElementById("aim1<data:post.id/>");
var obj1=document.getElementById("aim2<data:post.id/>");
var s=obj1.innerHTML;
var t=s.substr(0,s.length/2);
var r=t.lastIndexOf(" ");
if(r>0) {obj0.innerHTML=s.substr(0,r);obj1.innerHTML=s.substr(r+1);}
</script>


Now replace <!-- Your AdSense code here --> with your desired adsense code.Note that when you add the Adsense code, you must Encode it with Encoder.

Now, when you see your posts, you will see Adsense ads appearing in the middle of your blogger posts.

I think this is the best place in the whole template for Adsense.You will soon notice that 80% of your clicks will genearated from this Area.Good Luck!

Adding Introductions

Sometimes a little introductory paragraph or two helps "break the ice" between you and your readers, so they know what they are about to read, rather than just guessing based on one or two "label" words. You can see the new hack in effect on my site. Select on "Blogger Beta"->"My Hacks", for example, will display a little introduction first, then all the hack articles.

Below are the steps on how to implement this hack. As usual, make a template backup copy, then try it on your test blog first. Also, remember to check on "Expand Widget Templates."




Step 1: Add "introduction" function to Blog1 widget

First, locate the widget by looking for this line:

<b:widget id='Blog1' locked='false' title='Blog Posts' type='Blog'>

Once you see it, look for this line:

<b:includable id='main' var='top'>

Then paste this code right in front of it:

<b:includable id='sub-introduction' var='data:posts'>
<!-- **Introduction Hack - by Hoctro 10/2006 hoctro.blogspot.com ** Step 1 **

**** -->
<b:if cond='data:blog.pageType != "item"'>
  <b:loop values='data:posts' var='post'>
  <!-- Check for Homepage case -->
    <b:if cond='data:blog.url == data:blog.homepageUrl'>
      <b:if cond='data:post.title == "Introduction"'>
        <div class='post'>
          <div class='post-body'>
            <p><data:post.body/></p>
          </div>
        </div>
      </b:if>
    </b:if>
  <!-- Check for matched labels -->
  <b:loop values='data:post.labels' var='label'>
    <b:if cond='data:post.title == data:label.name'>
      <div class='post'>
        <div class='post-body'>
          <p><data:post.body/></p>
        </div>
      </div>
    </b:if>
 </b:loop>
</b:loop>
</b:if>
</b:includable>


Step 2: Modify the main includable of Blog1 widget

Scroll down to this line again,


<b:includable id='main' var='top'>


then look for the portion of code that starts and ends with these lines,



  <div id='blog-posts'>


...

  <!-- navigation -->
  <b:include name='nextprev'/>





You are going to replace everything in between with these lines,


<!-- **Introduction Hack - by Hoctro 10/2006 hoctro.blogspot.com ** Step 2 **

**** -->
   <b:include name='sub-introduction' values='data:posts'/>
    <b:loop values='data:posts' var='post'>
      <b:if cond='data:post.title == "Introduction"'>
        <b:if cond='data:blog.pageType == "item"'>
          <b:include data='post' name='postQuickEdit'/> 
          <b:include data='post' name='post'/>
        </b:if>
      <b:else/>
        <b:if cond='data:post.dateHeader'>
          <h2 class='date-header'><data:post.dateHeader/></h2>
        </b:if>
        <b:include data='post' name='postQuickEdit'/> 
        <b:include data='post' name='post'/>
        <b:if cond='data:blog.pageType == "item"'>
          <b:if cond='data:post.allowComments'>
            <b:include data='post' name='comments'/>
          </b:if>
        </b:if>
       </b:if>
    </b:loop>
  </div>


Step 3: Name your new introductory posts with "special" titles

Name your "special" new introductory posts' titles with exactly the same label names. for example, for the introductory post of "My Hack" to show correctly on my homepage, I had to name the title as "Blogger_Beta*My_Hacks" (I use my own's two level tab hack, hence the star (*) symbol in the middle) Also, after composing this special post, you need to change the date to some time in the past, so it will not show up as the latest. Also, if your introductory post has more than one label (which you shouldn't do,) make sure the last label is the same as the post's title.



here is the result,




For an introduction in your homepage, you will need something different. You need to create a post with the title "Introduction", do not assign a label (leave it blank), and set the date to a distant future! (I owe Hans from "Beautiful Beta" for this "set-in-a-future-date", by the way. Thanks! Hans.) This will make sure the post always includes in the homepage's post collection, thus it will show up. When displayed, this post will not show a title nor allow any comment from the readers.



Here is the result,



That's all it takes to have introductory paragraphs to show up on your blog. I hope you will able to make use of this hack.


Technical Comments:


Below are my technical comments, explaining the hack's logic. If you are interested in then read on. You're not required to understand my explanations to make it work on your blog.

1. I'm glad I am finally able to write another hack without the help of JavaScript. There is nothing wrong with JavaScript, it's just that stretching beta's own simple language is really fun. Indeed, beta's template doesn't need any Javascript at all, and it still looks great.

2. In Step 1: the "introduction" function, I create a loop, thus in effect make Blog1 loops through its post collection twice. That's how the introductory post can bubble up to be the first in the list. Inside the loop, I have two cases:

-If the reader is at homepage, then check to see if one of the post has the title of "Introduction." If so, prints the body only. This post must not have a label assigned.

- Next, I create another loop to go thru all the labels, and if one of them match the post's title, then also prints the body.

3. In Step 2, the goal is completely different. We want the introduction not to show up twice, yet at the same time it must be visible in the item page, if someone clicks on it from the archived list, hence the if-then-else structure.

I hope you will find some good use of both the hack and its source code as well.

Have a wonderful day.

Hoctro
(10/8/2006)


Make Random Banners for Blogspot

Swirls Vector Graphics Set

Have you ever visited a website or a blog? And when you refresh or reload it, the banners of header change in turn or randomly. If you have never visited it so far, you can visit http://jaya-example.blogspot.com. Try to refresh the pages a few times or click the links available in that blog so that the pages can be reloaded. Look at the banners or images in the header; they can appear in turn randomly, right. This random header banners can give new situation in our blog or website. Would you like to know how it happens? Just read the rest of this posting, ok!

  1. First Step

The first step is that you must have some banners; three, four or five banners depend on your will. To make the banners, you can use some program, for example adobe Photoshop, CorelDraw and others. I am sorry because I am not the expert of making banner, so I won't explain here. Just find them in some banner provider or seller in the internet.

  1. Second Step

In the second step, you have to upload the banners in hosting you usually save the images, for example www.photobucket.com.

After the uploading is finished, copy the URL Address of the banners and paste them in notepad or another text editor. These URL address will be inserted into the script that I will give

  1. Third Step

In the third step, you have to insert into the template code you have. The script is

 

<script type="text/javascript">
var banner= new Array()
banner[0]="bannerURL0"
banner[1]="bannerURL1"
banner[2]="bannerURL2"
banner[3]="bannerURL3"
banner[4]="bannerURL4"
banner[5]="bannerURL5"
banner[6]="bannerURL6"
banner[7]="bannerURL7"
banner[8]="bannerURL8"
banner[9]="bannerURL9"
var random=Math.floor(10*Math.random());
document.write("<style>");
document.write("#header {");
document.write(' background:url("' + banner[random] + '") no-repeat top left;');
document.write(" }");
document.write("</style>");
</script>

 

If you see the script above, I give 10 banners but 10 is not absolute, you can add as many banners as you want. But remember to you add the code in var random=Mat.

Because blogger template has two kinds of template, classic template and new template, placement of the code/script is different and I will divide the explanations into two parts. But before explaining the steps, I would like to give the sample code that contains I have uploaded and have the URL address. The URL addresses are:

http://i162.photobucket.com/albums/t253/rohman24/banner_1.gif
http://i162.photobucket.com/albums/t253/rohman24/banner_2.gif
http://i162.photobucket.com/albums/t253/rohman24/banner_3.gif
http://i162.photobucket.com/albums/t253/rohman24/banner_4.gif
http://i162.photobucket.com/albums/t253/rohman24/banner5.gif
http://i162.photobucket.com/albums/t253/rohman24/banner_6.gif
http://i162.photobucket.com/albums/t253/rohman24/banner_7.gif
http://i162.photobucket.com/albums/t253/rohman24/banner_8.gif
http://i162.photobucket.com/albums/t253/rohman24/banner_9.gif
http://i162.photobucket.com/albums/t253/rohman24/banner_10.gif

 

And the banner sample is as follows (the image has been minimized]

























The script sample of the banners is:




<script type="text/javascript">
var banner= new Array()
banner[0]="http://i162.photobucket.com/albums/t253/rohman24/banner_1.gif"
banner[1]="http://i162.photobucket.com/albums/t253/rohman24/banner_2.gif"
banner[2]="http://i162.photobucket.com/albums/t253/rohman24/banner_3.gif"
banner[3]="http://i162.photobucket.com/albums/t253/rohman24/banner_4.gif"
banner[4]="http://i162.photobucket.com/albums/t253/rohman24/banner_5.gif"
banner[5]="http://i162.photobucket.com/albums/t253/rohman24/banner_6.gif"
banner[6]="http://i162.photobucket.com/albums/t253/rohman24/banner_7.gif"
banner[7]="http://i162.photobucket.com/albums/t253/rohman24/banner_8.gif"
banner[8]="http://i162.photobucket.com/albums/t253/rohman24/banner_9.gif"
banner[9]="http://i162.photobucket.com/albums/t253/rohman24/banner_10.gif"
var random=Math.floor(10*Math.random());
document.write("<style>");
document.write("#header {");
document.write(' background:url("' + banner[random] + '") no-repeat top left;');
document.write(" }");
document.write("</style>");
</script>

And below are the steps to make random banners;

For Classic Template

  1. Log in into blogger with your id
  2. Click Template
  3. Click Edit HTML
  4. Copy the whole HTML code and paste into notepad and save. It is aimed to anticipate if you make mistake in editing your template and you still have the back up.
  5. Copy and pate the following code under <div id='header'>


    <script type="text/javascript">
    var banner= new Array()
    banner[0]="http://i162.photobucket.com/albums/t253/rohman24/banner_1.gif"
    banner[1]="http://i162.photobucket.com/albums/t253/rohman24/banner_2.gif"
    banner[2]="http://i162.photobucket.com/albums/t253/rohman24/banner_3.gif"
    banner[3]="http://i162.photobucket.com/albums/t253/rohman24/banner_4.gif"
    banner[4]="http://i162.photobucket.com/albums/t253/rohman24/banner_5.gif"
    banner[5]="http://i162.photobucket.com/albums/t253/rohman24/banner_6.gif"
    banner[6]="http://i162.photobucket.com/albums/t253/rohman24/banner_7.gif"
    banner[7]="http://i162.photobucket.com/albums/t253/rohman24/banner_8.gif"
    banner[8]="http://i162.photobucket.com/albums/t253/rohman24/banner_9.gif"
    banner[9]="http://i162.photobucket.com/albums/t253/rohman24/banner_10.gif"
    var random=Math.floor(10*Math.random());
    document.write("<style>");
    document.write("#header {");
    document.write(' background:url("' + banner[random] + '") no-repeat top left;');
    document.write(" }");
    document.write("</style>");
    </script>




  6. Save the full template
  7. Finished

For New Template

  1. Log in into blogger with your id
  2. Click Layouts
  3. Click Page Elements tab
  4. Click Add a Gadget
  5. Click HTML/JavaScript
  6. Copy pastes the following code into it.


    <script type="text/javascript">
    var banner= new Array()
    banner[0]="http://i162.photobucket.com/albums/t253/rohman24/banner_1.gif"
    banner[1]="http://i162.photobucket.com/albums/t253/rohman24/banner_2.gif"
    banner[2]="http://i162.photobucket.com/albums/t253/rohman24/banner_3.gif"
    banner[3]="http://i162.photobucket.com/albums/t253/rohman24/banner_4.gif"
    banner[4]="http://i162.photobucket.com/albums/t253/rohman24/banner_5.gif"
    banner[5]="http://i162.photobucket.com/albums/t253/rohman24/banner_6.gif"
    banner[6]="http://i162.photobucket.com/albums/t253/rohman24/banner_7.gif"
    banner[7]="http://i162.photobucket.com/albums/t253/rohman24/banner_8.gif"
    banner[8]="http://i162.photobucket.com/albums/t253/rohman24/banner_9.gif"
    banner[9]="http://i162.photobucket.com/albums/t253/rohman24/banner_10.gif"
    var random=Math.floor(10*Math.random());
    document.write("<style>");
    document.write("#header {");
    document.write(' background:url("' + banner[random] + '") no-repeat top left;');
    document.write(" }");
    document.write("</style>");
    </script>



  7. Click SAVE CHANGES
  8. Finished

 

Remember, the codes above are only sample, please change the URL address of the banners with your own URL address of the banners.

There might be some templates and the header banners are not suitable with your interest or will. Actually, you can change the size of the header. For example, I use minima template;

 

@media all {
#header {
width:660px;
margin:0 auto 10px;
border:1px solid #ccc;
}

 

The code above show that the width of the banner header id 660 pixel,s we can change that value with our interest value. And the height of the banner header is not defined. Now, in order to make our banner match with our own, we must insert the additional code as a definition.

For example; the height you want is 150px, then the additional code is height:150px; so the code above will look like below;




@media all {
#header {
width:660px;
height:150px;
margin:0 auto 10px;
border:1px solid #ccc;
}




Each template is different but blogger template usually write #header in its HTML code in the template.


What is a widget, after all? (Part 2)

This is the second part of my article,in which I explain what consists of a widget. Below is again the code from the last time.

br />
01. <b:widget id='Label1' locked='false' title='Labels' type='Label'>
02. <b:includable id='main'>
03.   <b:if cond='data:title'>
04.     <h2><data:title/></h2>
05.   </b:if>
06.   <div class='widget-content'>
07.     <ul>
08.     <b:loop values='data:labels' var='label'>
09.       <li>
10.         <b:if cond='data:blog.url == data:label.url'>
11.           <data:label.name/>
12.         <b:else/>
13.           <a expr:href='data:label.url'><data:label.name/></a>
14.         </b:if>
15.         (<data:label.count/>)
16.       </li>
17.     </b:loop>
18.     </ul>
19.
20.     <b:include name='quickedit'/>
21.   </div>
22. </b:includable>
23. </b:widget>


Now that we know a little bit what that does, what can we do to alter its appearance, or improve it to make the widget looks different?

1. Omit a feature:

As a simplest hack of all, just remove line 15, where the line tells Blogger to print the label count along with the label name, and you're done.

As a good precaution, if you're not sure if you really want to remove the line or not, you could comment it out, so Blogger could ignore the line (or lines) while reading the template. to do that, put these special code <-- and --> in front and at the end of the line

<!-- (<data:label.count/>) -->

Here's the result:



2. A simple change of appearance:

Instead of a list, we can simply make it a paragraph, consists of many labels, separated by a character. To do that, change the code between line 7 and 18 to become:


07.     <div>
08.     <b:loop values='data:labels' var='label'>
09.       <span>
10.         <b:if cond='data:blog.url == data:label.url'>
11.           <data:label.name/>
12.         <b:else/>
13.           <a expr:href='data:label.url'><data:label.name/></a>
14.         </b:if>
15.         <!--(<data:label.count/>) -->
16.       </span> &nbsp;*&nbsp;
17.     </b:loop>
18.     </div>


Here's the result:



What we've done is to rename the "ul" (unordered list) tags to become "div" tags, and to rename "li" tags for each label to become "span" tags. Finally, the "&nbsp;*&nbsp;" at the end of line 16 is to separate labels with "*"

A much improvement of this code would be to add JavaSript code to dynamically examine the label count, then adjust the span tag to show different text height per label, and other extra twists such as color, or font, to make this little hack become a label cloud.

3. Adding a simple tweak to existing code:

Suppose you want your reader to open a new window every time he or she clicks on the label, simply add this code to line 13:

13.           <a expr:href='data:label.url' target='_blank'><data:label.name/></a>

You can apply this trick to other widget as well. One of the question I got recently from a reader is how to create a new window every time the user clicks on a link for the link list widget. To do so, look for the widget:

<b:widget id='LinkList1' locked='false' title='Link List' type='LinkList'>

then this line,

<li><a expr:href='data:link.target'><data:link.name/></a></li>

and alter it to become:

<li><a expr:href='data:link.target' target='_blank' ><data:link.name/></a></li>


4. Mixing of the above:

Yet, there are also ways to mix and match elements to create new solutions. For example, suppose we like our "tags/labels/categories" naming, but we're not sure if the rest of the world have similar names. One way to quickly check that is to use our labels, but the link background is a combination of technorati syntax (http://www.technorati.com/tag/)instead of the default blogger tag search, and our label. Simply change line 13 to show like this, and the result is sweet:

<a expr:href='"http://www.technorati.com/tag/" + data:label.name'><data:label.name/></a>


5. Reorganizing code and add CSS to turn the label widget into a completely different thing:

This takes more thinking upfront, but the result is sweet. You can see a demonstration of such hack here:
http://hoctro.blogspot.com/2006/09/tweaking-new-blogger-turning-labels.html
.


6. Combining with JSON callback technique:

Since we know the label name, we can send the name to blogger to receive data back on all the posts belong to each label. The result would be like a site map, where each label shows its belonging post headers. I might implement this hack in the future, as all the background code is already existed in my other JSON hacks.

Altering the logic code of a widget


Surprisingly enough, it takes only two major language constructs to convey most of the blog's data and transforming it into a webpage, and another two constructs to organize code into understandable chunks and to call them. They are:

1. The If statement

2. The Loop statement

3. The includable/include statements


  • I think this is a major achievement of the template designers. Even though this is not a new idea, as it is already implemented in other languages such as PHP, and even the old blogger, it is still a very interesting and remarkable achievement.

  • The new Blogger template indeed uses XHTML extensively, so that when the page loads, what it sees in term of HTML tags, it will render exactly like that to the sceen. When it encounters a b:if and b:loop tags, on the other hand, it will render the suitable chunk of HTML or yet other template code based on the situation at hand. This fact alone makes great use of existing HTML tags, as the template designers safely ignore basic language features such as file I/O access, math, database retrieval syntax and command, etc.

  • Each widget also acts in its own isolated island, as none of the code from one widget could be accessed from another. To do that, you need to cut and paste the code. This way, bugs are isolated and easier to debug.

  • In Blogger template, as the same case with Classic Blogger, there is no construct on how to write data back to the server. I think this is such an excellent idea, as the blogger doesn't have to deal with another yet level of complexity.

  • Another thing that I like about the New Blogger template is that names are broken down into understandable "sub" names, instead of the Classic Blogger way. This makes it easier to work with, or at least to guess the possible name for the feature.


The future of Widgets

Widgets, except the "Blog Posts" and "Archived" ones, are relatively easy to understand and to hack, once you know the concepts. They are also very limited for "tweaking" activities, since there are not much data inside them, and there are basically two mentioned simple constructs: if and loop. But once they are combined with the power of JavaScript and JSON, as seen in the NEO template from Ramani and from some other recent hacks, they are getting really interesting to think about and to implement.

And don't count Blogger out either. There might be other new widgets already in store for us, they are just waiting for the green light to see the day.

The future of the New Blogger template and its wonderful widgets, in my mind, looks pretty good as there are plenty of room to play with and to improve.

Cheers,

 

blogger templates | Make Money Online