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

Thứ Ba, 31 tháng 12, 2013

Blogger Global Layout Data Tags Codex


I usually create many templates for Blogger Items. I write this tip to help myself save the time each time need to find a right data tag. Hope also help you.

List of Global Layout Data Tags

Blog Title

<data:blog.pageTitle/>
This tag will show your Blog Title. You can change value of this tag by access: Settings/ Basic / click Edit link on Title field, type the title you want and click Save changes.

Page name

<data:blog.pageName/>
This tag will show your Page Title, in general, it’s your post title or page title you typed when publish.

Page type

<data:blog.pageType/>
This tag will show the type of current page. This tag has below values
  • index - mean the current page is home, label or search page.
  • static_page – mean the current page is a static page
  • item – mean the current page is a post.
  • archive – mean the current page is time archive page
  • error_page – mean the current page is 404 page.

Blog Description

<data:blog.metaDescription/>
This tag will show the description of your blog if the current page is home page, or show the description of post if its type is static_page or item
To change the description for home page, access Settings / Search preferences. one Meta tags section, click Edit link on Description field, check Yes at Enable search description? option. Then input your blog description and click Save changes.
To input the description for your post, before publish a post, look on right side, you will see Search Description option, click and input the snippet for the post.

BLOG URL

<data:blog.url/>
This tag will show the canonical URL of the current page. Canonical is current URI of the page without extend paramenters. Example: http://bloggeritems.com?id=100 => canonical URL = http://bloggeritems.com

Home URL

<data:blog.homepageUrl/>
This tag will show the home URL of your blog.

Blog encode

<data:blog.encoding/>
This tag will show the encoding that’s using in your blog, common is “UTF-8″.
LANGUAGE DIRECTION
<data:blog.languageDirection/>
This tag will show either “ltr” or “rtl” for left-to-right and right-to-left languages, respectively. This tag value will change base on the language that you set up for your blog.

Feed links

<data:blog.feedLinks/>
This tag is only effect on header of page (before </head> tag). The result of this code will like below:
<link rel="alternate" type="application/atom+xml" title="Blogger Items - Atom" href="http://bloggeritems.com/feeds/posts/default" />
<link rel="alternate" type="application/rss+xml" title="Blogger Items - RSS" href="http://bloggeritems.com/feeds/posts/default?alt=rss" />
<link rel="service.post" type="application/atom+xml" title="Blogger Items - Atom" href="http://www.blogger.com/feeds/5248366312679450270/posts/default" />
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.blogger.com/rsd.g?blogID=5248366312679450270" />

Usage

Global Layout Data tags are xml codes that’re available to use in all place in a Blogger template code.
You can you a tag as direct out to HTML code:
<data:blog.pageTitle/>
Or use in if condition like this
<b:if cond="data:blog.pageType == &quot;index&quot;>Your stuff of code here</b:if>
Or use as an attribute of HTML element with expr: before the attribute name
<body exrp:class='data:blog.pageType'>
Note: the preview page will work similar as homepage URL but has type is item.


Right way to embedded direct javascript code to Blogger template


I just usually forgot how to embedded javascript code to my Blogger templates. So I just want to share with you as a short quote and also help me each time I need add Js to a template. This tip always helps me prevent XML error when save template code.
At first, Access your blog dashboard, choose Template. Then click Edit HTML. Not, insert before </head> tag or </body> tag with your javascript wrapper code like below:
<script type='text/javascript'>
//<![CDATA[
// Place your javascript code here
//]]>
</script>
Then click Save template

Blogger host and direct embedded CSS / Javascript comparison


Blogger has no hosting for us to host css and javascript files. So we always find a free or cheap hosting to host our files. But before host them, we must compare the page speed to sure that way we host css / javascript files is faster than the way we embed them direct to our template HTML.
In this comparison, I will use Google Drive as free host for our files. At first, you must know how to upload your css / javascript files to your Google Drive.

Uploading files to Google drive

Of course, you need a Gmail account to login to your Google Drive. After logged in, click Upload button to upload your css / javascript files. In this test, I will upload two files: bloggeritems.com.css (100KB) and bloggeritems.com.js (500K)
host-css-javascript-01
host-css-javascript-02
After uploaded, you will see Upload Complete window. Click Share link of the file you had just uploaded to show Sharing settings window.
host-css-javascript-03
You can also click a file name and then click Share button to show Sharing settings window.
host-css-javascript-03-other
In Sharing settings window, at Who has access, click Change… link of Private – Only the people listed below can access option.
host-css-javascript-04
In next window, check to choose Public on the web option, then click Save.
host-css-javascript-05
After that, the window will come back the Sharing Settings window that allows you copy Link to share url. We will use this url for next section.
host-css-javascript-06

Add uploaded files to template code

Before you can use the link that copied above, you must replace “docs.google.com/file/d” to “googledrive.com/host” and remove “/edit?usp=sharing” in the link. Below is an example:
From this: https://docs.google.com/file/d/0B6J4nBUXfVekel9xZ0JrZ25zT28/edit?usp=sharing
To this: https://googledrive.com/host/0B6J4nBUXfVekel9xZ0JrZ25zT28
Use the replaced link to embedded to your template code.
With css:
<link rel="stylesheet" type="text/css" href="https://googledrive.com/host/0B
With javascript:
<script type="text/javascript" src="https://googledrive.com/host/0B6J4nBUXfVekel9xZ0JrZ25zT28"></script>

Comparing host and direct embedded code speed

After I used PageSpeed Insights to test, the result surprised me. Below is the result when we host 2 files on Google Drive:
host-css-javascript-07
PageSpeed Insights Result with hosted files from Google Drive
The below is with direct embedded:
host-css-javascript-08
PageSpeed Insights with Direct embedded code
Yes, the result is too different. With hosted files from Google Drive, the speed is only47/100. But if you use direct code embedded to template, the speed will be 84/100, too fast.
We are talking about Google Drive hosting, one of fastest and stable hosting of World, but as you see, the test showed us that the Blogger hosting is better than. So, that’s why I always embedded javascript and css direct in template code, and may be your customers also love that way (many customers used PageSpeed Insights to test my templates, so I must sure they satisfy with result).

Conclusion

Never use Google Drive to host css or javascript files, it’s slow. Just host your files in case you can not embedded it direct in Blogger template code, example: flash, media files, …
Wish you always enjoy your blog as the best way!

Add jQuery to your Blogger/Blogspot blog template


JQuery is the very important thing to make effects, animation and cool functions for your blog. Many Blogger plugins are also using jQuery. Just embed jQuery into our blog template, it will help us save the time to develop and also provide us many option to make beautiful effects on our designs.
A jQuery file is only about 100KB and available to cached, so don’t wory about the speed of your page after embedded it.
To embed jQuery, please access your blog Template and click Edit HTML
Open template editor
Open template editor
Before insert jQuery, you must check that is it alreay installed in your template?Please find “https://ajax.googleapis.com/ajax/libs/jquery” if you found nothing, mean you need to continue, if yes, just stop and do nothing because your template had a jQuery library.
In template Editor window, find the tag </head> and insert before it with the below line:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jq
Then click Save template.