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.
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,
This will workout well and the number of lines of code is considerably reduced.
See related posts:
<!--See related posts appear only if required-->
<b:if cond='data:post.labels any (label => label.name in ["Blogger Customizations","Blogger Tricks"])'>
<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 ["Blogger Customizations","Blogger Tricks"])" var="label">
<li><a expr:href='data:blog.homepageurl + "/search/label/" + data:label.name'><data:label.name/></a></li>
</b:loop>
</ul>
<!--Un-ordered list tag begins-->
<b:if cond='data:post.labels any (label => label.name in ["Blogger Customizations","Blogger Tricks"])'>
<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 ["Blogger Customizations","Blogger Tricks"])" var="label">
<li><a expr:href='data:blog.homepageurl + "/search/label/" + 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 ["Blogger Customizations","Blogger Tricks","Custom Domains"])'>
<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 ["Blogger Customizations","Blogger Tricks","Custom Domains"])" var="label">
<li><a expr:href='data:blog.homepageurl + "/search/label/" + data:label.name'><data:label.name/></a></li>
</b:loop>
</ul>
<!--Un-ordered list tag begins-->
<b:if cond='data:post.labels any (label => label.name in ["Blogger Customizations","Blogger Tricks","Custom Domains"])'>
<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 ["Blogger Customizations","Blogger Tricks","Custom Domains"])" var="label">
<li><a expr:href='data:blog.homepageurl + "/search/label/" + 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
Post a Comment