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
-
Featured Blogger site: Renew PilatesRenew Pilates in Easthampton, MA provides private, semi-private and small group pilates instructio…
-
Question: Where do my images get stored when I add them to my blog?When you first sign in and create a new blog in Blogger, you might not know this, but you are unlea…
-
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…
-
Group blogging and blogging in the classroomWe normally talk about blogging as a personal project or a business project; unfortunately we often…
-
Featured Blogger Site: Our own Confluent Forms LLC!You know the maxim that the cobbler's children have no shoes? No longer! After years of discuss…
-
Tip: Understanding the Atom/RSS feeds created by BloggerIf you've heard of RSS feeds, you probably know that they're a way for your site's fans…
-
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