【问题标题】:prepare all the posts for the loop in Google blogger template?为 Google 博客模板中的循环准备所有帖子?
【发布时间】:2015-10-24 12:43:50
【问题描述】:

我正在阅读博主帮助文章 (Layout data tags) 并发现 <data.posts/> 将包含所有帖子。

但是从模板中看不出什么,还有一个错误TEMPLATE ERROR: No dictionary named: '' in: ['blog', 'skin', 'view']

所以这是我的问题,我如何从模板中循环所有最近的帖子?

这是我所做的:

<b:loop var='thisPost' values='data:posts'>
  <h2>
    %3Ca%20href%3D%22<data:thisPost.url/>%22%3E<data:thisPost.title/>%3C%2Fa%3E
  </h2>
</b:loop>

它不工作!有什么想法吗?

更新:

在小部件中,循环不起作用!这是我的代码:

<b:section class='main' id='main' name='Main' showaddelement='yes'>
    <b:widget id='Blog1' locked='false' title='Blog Posts' type='Blog'>
        <b:includable id='allposts' var='i'>
          <b:loop var='thisPost' values='data:posts'>
            <h2>
              <a expr:href='data:thisPost.url'><data:thisPost.title/></a>
            </h2>
          </b:loop>
        </b:includable>
    </b:widget>
</b:section>

【问题讨论】:

    标签: xml blogger


    【解决方案1】:

    您将此代码/循环放在哪里?

    除非在 section: mainwidget: Blog1 内部,否则它将无法工作

    <b:section class='main' id='main' name='Main' showaddelement='yes'>
        <b:widget id='Blog1' locked='false' title='Blog Posts' type='Blog'>
            <b:includable id='...' var='...'>
    
                // it will only work inside here
    
            </b:includable>
        </b:widget>
    </b:section>
    

    更新

    Blogger 在任何小部件中输出 &lt;b:includable id='main'&gt; 内的内容。您可以在&lt;b:includable id='main'&gt; 旁边添加尽可能多的&lt;b:includable id='...'&gt;。如果您不使用&lt;b:include name="..."&gt; 直接或间接将它们链接到&lt;b:includable id='main'&gt;,它们将不会执行。这里include 中的name 等于includable 中的id

    <b:section class='main' id='main' name='Main' showaddelement='yes'>
        <b:widget id='Blog1' locked='false' title='Blog Posts' type='Blog'>
    
            <b:includable id='main' var='top'>
               <b:include name='allposts'/>
            </b:includable>
    
            <b:includable id='allposts'> <!-- you can remove var="i" -->
                <b:loop var='thisPost' values='data:posts'>
                    <h2>
                        <a expr:href='data:thisPost.url'><data:thisPost.title/></a>
                    </h2>
                </b:loop>
            </b:includable>
    
        </b:widget>
    </b:section>
    

    【讨论】:

    • @rakibtg 我也更新了我的答案,您的代码很好,您所要做的就是将其包含在&lt;b:includable id="main"&gt; 中,如答案中所述
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多