Looping through the listing of blog posts
<b:loop values='data:posts' var='post'>
Inside the loop data:posts changes to data.post (determined by the value of var, set here as var='post')
We can reference the id of the current post in the loop as <data:post.id />
</b:loop>
Looping through the listing of blog posts with an additional index
<b:loop values='data:posts' var='post' index='i'>
The id of the current post in the look is <data:post.id />
The position of this post in the loop index is <data:i />
We can run a IF statement against this value like so:
<b:if cond='data:i == 2'>
This is the post contained in the loop at position 2, which in an array is Post #3 (arrays start counting at 0)
</b:if>
</b:loop>
"is first" variables
There are a number of "is first" variables in Blogger that are unfortunately not declared on the official variable list.
data:post.isFirstPost
This variable can be used to show a different behavior on an index page for the first post, by placing it within the data:posts loop, like so:
<b:loop values='data:posts' var='post'>
<b:if cond='data:post.isFirstPost == "true"'>
first psot!
</b:if>
</b:loop>
data:post.isDateStart
This variable is used to group posts by date, often found on a Blogger site's index pages, where it shows all posts under one day/date, then moves to the next day/date without repeating that value.
data:post.firstImageUrl
This variable shows the URL of the first image used in the blog post. This is often handy for creating an index page of image thumbnails. But while the "thumbnail" variable (data:post.thumbnailUrl) only shows a 72 pixel square and only works for Google hosted images, this firstImageUrl variable shows the full image url and can be used for non-Google-hosted images.
data:post.sharePostUrl
This variable displays the absolute url for a blog post in question. Used in the social media share buttons, but can certainly be used in other cases.
data:post.snippet
This variable displays the first 140 characters of a blog post, or what comes before a jump break, whichever is first.
Examples in use:
<b:if cond='data:blog.metaDescription != ""'>
<meta expr:content='data:blog.metaDescription' name='og:description'/>
<b:else/>
<meta expr:content='data:post.snippet' property='og:description'/>
</b:if>
<meta expr:content='data:post.thumbnailUrl' itemprop='image_url'/>
The above code will show the first image URL as the snippet's thumbnail, along with either the post's meta description (search description in the blog post) or, if none, the 140 character snippet.
Popular
-
Tip: How do I remove the Blogger bar at the top of my site?This is, far and away, the #1 question we're asked when people see the work we've done with…
-
Is Wordpress better than Blogger for SEO? No answer.If only we had a dollar for each time we were asked this question, or were told that everyone shoul…
-
Tip: Updated way to remove the Blogger NavbarIt's been a while since we took a look at the Blogger navbar, mainly because we simply got in t…
-
Question: Why is my Blogger blog not displaying correctly in IE 9?As web developers we learn to live with what we call "cross-browser compatibility" issues…
-
Tip: Better titles for your article posts and pagesOne of the simplest ways you can improve your Blogger site's search engine optimization (SEO), …
-
Featured Blogger Site: Rebekah Brooks JewelryRebekah Brooks is a small handmade jewelry company based in Massachusetts. Fulfilling a lifelong i…
-
Tip: Making index page images link to the post pageThis tip mainly applies to blogs that take advantage of jump breaks in their posts as a way to shor…
Post a Comment
Post a Comment