Can you customize your blog to display only the very first post tag on Blogger?

I have experience with HTML and CSS , but the correct coding like Java, JS and PHP . I am new, plus this is the first time I created Blogger Template / Site from scratch, so this is a lot of trial and error. I tried to search for an answer, but I could not find an answer that seemed to me to be relevant to what I was looking for.

As a standard, we know that Blog1 widget will show your most recent entry in its entirety on the landing page, along with the author’s details, comments and labels in the footer. My question is : can you change the code to only display the first label that will be displayed at the bottom of the message?

As a standard, this is the syntax used to call the list of shortcuts encoded by the native blogger:

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

Although I may have changed the b: loop to say that ab: include will stop the blogger requiring more shortcuts, and maybe only one, but when I changed this, he basically stopped the entire blog from displaying!

I want only "Labels: Label1" instead of "Labels: Label1, Label2, Label3, etc." without resorting to restricting the number of tags to just one.

Thanks in advance to everyone who answers and helps.

Mark

+5
source share
2 answers

You can use the index attribute, which gives the postal index zero index through the loop

 <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> 
+1
source

Update:. An easier way to achieve what you need can be done with this code -

 <data:postLabelsLabel/> <a expr:href="data:post.labels[0].url" ><b:eval expr='data:post.labels[0].name'/></a> 

Only one conditional statement is required to restrict labels. The above code will be modified as follows:

 <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 used the conditional data:label.isLast to print the label only if it is the last in the record (if there is only one label, then this will be printed). Blogger organizes tags alphabetically and provides no control over the sort order.

For example, if a column has labels as follows "Labels: A, B, C" , then after changing the code to above, the final result will be Labels: C "

+1
source

Source: https://habr.com/ru/post/1264059/


All Articles