related-posts do not load until this line of code is refreshed in Blogger Templating language

18 Views Asked by At
<b:includable id='JetRelatedPost' var='post'>
<b:if cond='data:post.labels'>
<div class='custom-posts visually-hidden related-posts' data-func='related_temp' data-items='10' data-shuffle='4' data-title='أخبار ذات صلة' expr:data-no-item='data:post.url.canonical'><b:with value='data:post.labels where (l =&gt; l.name not contains &quot;#&quot;)' var='labels'><b:loop index='i' values='data:labels' var='label'><data:label.name/><b:if cond='data:i != data:labels.size - 1 '>,</b:if></b:loop></b:with></div>
</b:if>             
</b:includable>

Here's an explanation of what happens in the code:

  1. <b:includable id='JetRelatedPost' var='post'>: This line declares an includable section with the ID 'JetRelatedPost' that can be included and passed a variable named 'post'.

  2. <b:if cond='data:post.labels'>: This line starts an if statement that checks if the 'post' variable has any labels.

  3. <div class='custom-posts visually-hidden related-posts' data-func='related_temp' data-items='10' data-shuffle='4' data-title='أخبار ذات صلة' expr:data-no-item='data:post.url.canonical'>: This line defines a div element with multiple attributes. It sets the class as 'custom-posts visually-hidden related-posts' and sets various data attributes used for handling related posts functionality.

  4. <b:with value='data:post.labels where (l =&gt; l.name not contains &quot;#&quot;)' var='labels'>: This line starts a 'b:with' statement that filters the 'post.labels' to exclude any labels containing the '#' character. The filtered labels are assigned to the variable 'labels'.

  5. <b:loop index='i' values='data:labels' var='label'>: This line starts a 'b:loop' statement that iterates over the 'labels' variable, assigning each label to the variable 'label'. The 'index' attribute tracks the loop index, and the 'values' attribute specifies the source of values (in this case, 'data:labels').

  6. <data:label.name/>: This line outputs the name of the current label being iterated within the loop.

  7. <b:if cond='data:i != data:labels.size - 1 '>,</b:if>: This line adds a comma after each label except for the last label in the loop. It checks if the current index 'i' is not equal to the size of the 'labels' array minus one, indicating that it is not the last label.

  8. </b:loop>: This line ends the loop.

  9. </b:with>: This line ends the 'b:with' statement.

  10. </div>: This line closes the div element.

  11. </b:if>: This line ends the if statement.

The code essentially checks if the 'post' variable has labels, and if so, it creates a hidden div element with related posts functionality. The loop within the div outputs the names of the labels separated by commas, excluding labels that contain the '#' character.

i need the code to display the related-posts instead of the labels.

0

There are 0 best solutions below