Skip to main content

Related posts. Looping with Multiple Labels

Enhancing the Related Posts code, we will now move on with Loops on multiple labels. It's advised to read Related posts with multiple conditions and then continue to read this post to understand things better.

<!--See related posts appear only if required-->
<b:if cond='data:post.labels any (label => label.name in [&quot;Blogger Customizations&quot;,&quot;Blogger Tricks&quot;])'>
<b>See related posts:</b>
</b:if>

<!--Un-ordered list tag begins-->
<ul>

<!--This loop should be passed with Labels to be filtered for Related posts-->
<b:loop values="data:post.labels filter (label => label.name in [&quot;Blogger Customizations&quot;,&quot;Blogger Tricks&quot;])" var="label">
        <li><a expr:href='data:blog.homepageurl + &quot;/search/label/&quot; + data:label.name'><data:label.name/></a></li>
</b:loop>

</ul>
<!--Un-ordered list tag begins-->

This loop takes care of linked lists and fits into all kind of posts. All we need to do is find the label name and added it in two places as highlighted in green.

Therefore, a third label can be added like below(yellow highlighted) and the code will look like,

<!--See related posts appear only if required-->
<b:if cond='data:post.labels any (label => label.name in [&quot;Blogger Customizations&quot;,&quot;Blogger Tricks&quot;,&quot;Custom Domains&quot;])'>
<b>See related posts:</b>
</b:if>

<!--Un-ordered list tag begins-->
<ul>

<!--This loop should be passed with Labels to be filtered for Related posts-->
<b:loop values="data:post.labels filter (label => label.name in [&quot;Blogger Customizations&quot;,&quot;Blogger Tricks&quot;,&quot;Custom Domains&quot;])" var="label">
        <li><a expr:href='data:blog.homepageurl + &quot;/search/label/&quot; + data:label.name'><data:label.name/></a></li>
</b:loop>

</ul>
<!--Un-ordered list tag begins-->

This will workout well and the number of lines of code is considerably reduced.

Comments

Popular posts from this blog

How to connect any other profile in "About me" widget?

In this article I am going to tell "How to connect any other profile in "About me" widget along with blogger or Google+?"

Facebook OG object debugger

Basically, while sharing a link for the first time, the object debugger stores the meta information in its databases so when you share again, instead of debugging the URL, it takes from its own database. So a shared URL even upon changing the description/image/title, does not get affected sooner.
So, to overcome this and see quicker results of custom description/ changing image/ changing blog or post title, facebook has a facility called the Open Graph Object Debugger.