How to show only label or last label of a post in Blogger?

How to show only label or last label of a post in Blogger?

Updated on 12 May

How to show only the first label of a post in Blogger

You can use index attribute which gives zero-based index of post labels through the loop

Method 1 (Recommended)


<b:if cond='data:top.showPostLabels and data:post.labels'>
    <data:postLabelsLabel/>
    <b:loop values='data:post.labels' index='i' var='label'>
        <b:if cond='data:i == 0'>
          <a expr:href='data:label.url' rel='tag'>
            <data:label.name/>
          </a>
        </b:if>
    </b:loop>
</b:if>

Method 2


<b:if cond='data:top.showPostLabels and data:post.labels'>
    <data:postLabelsLabel/>
    <b:loop values='data:post.labels' var='label'>
          <a expr:href="data:post.labels[0].url" ><b:eval expr='data:post.labels[0].name'/></a>
    </b:loop>
</b:if>

How to show only the last label of a post in Blogger


<b:if cond='data:top.showPostLabels and data:post.labels'>
    <data:postLabelsLabel/>
    <b:loop values='data:post.labels' var='label'>
        <b:if cond='data:label.isLast'>
            <a expr:href='data:label.url' rel='tag'>
                <data:label.name/>
            </a>
        </b:if>
    </b:loop>
</b:if>

I have used the conditional data:label.isLast to print the label only if it is the last one in the post (in case there is only one label, then that would be printed). Blogger arranges the labels in alphabetical order and doesn't provide any control over changing the sorting order.
For example, if the post has the labels as follows "Labels: A, B, C", then after changing the code to the one above, the end result would be "Labels: C"
Source:https://stackoverflow.com/questions/42155134/can-you-set-your-blog-to-show-only-the-very-first-label-of-a-post-in-blogger

0 comments for How to show only label or last label of a post in Blogger?

Cancel