调整 Blogger 的精选 Post 小工具以显示特定标签的最新帖子
Adapting Blogger's Featured Post Gadget to show recent posts of specific labels
标题基本上说明了一切。您是否知道如何调整 Blogger 的特色 Post 小工具,以便它可以只显示某个标签的最近 post,而不是显示我整个网站的最近 post?我只想要一个小部件,它可以显示我的一个标签中的最新 post(仅 1 个 post)。
这是我网站的 link。我所说的小工具在网站上称为随机 Post:http://newsotuniverse.blogspot.ca/
我还将为您 non-Blogger 用户提供一些网站代码,看看您是否可以解决问题:
<b:widget id='FeaturedPost1' locked='false' title='Random Post' type='FeaturedPost'>
<b:widget-settings>
<b:widget-setting name='showSnippet'>true</b:widget-setting>
<b:widget-setting name='showPostTitle'>true</b:widget-setting>
<b:widget-setting name='showFirstImage'>true</b:widget-setting>
<b:widget-setting name='useMostRecentPost'>true</b:widget-setting>
</b:widget-settings>
<b:includable id='main'>
<!-- Only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<b:include name='content'/>
<b:include name='quickedit'/>
</b:includable>
<b:includable id='content'>
<div class='post-summary'>
<b:if cond='data:showPostTitle and data:postTitle != ""'>
<h3><a expr:href='data:postUrl'><data:postTitle/></a></h3>
</b:if>
<b:if cond='data:showSnippet and data:postSummary != ""'>
<p>
<data:postSummary/>
</p>
</b:if>
<b:if cond='data:showFirstImage and data:postFirstImage != ""'>
<img class='image' expr:src='data:postFirstImage'/>
</b:if>
</div>
<style type='text/css'>
.image {
width: 100%;
}
</style>
</b:includable>
</b:widget>
如果有人能提供帮助,将不胜感激。提前致谢!
更新: 我更新了它现在过滤标签 label1
的帖子的代码。
我认为不可能,因为您无法访问标签 属性 来自 featured Post 数据元素, 但是 您可以用 Blog Widget 替换 FeaturedPost Widget,代码如下:
<b:widget id='Blog2' locked='true' title='FeaturedBlog' type='Blog' >
<b:includable id='main'>
<div class='post-summary'>
<b:with var="filteredData" value="data:posts filter (p => p.labels any ( l => l.name == "label0" ))">
<b:loop values='data:filteredData' var='post' index='index'>
<b:if cond='data:index == "0"' >
<h3><a expr:href='data:post.url'><data:post.title/></a></h3>
...
</b:if>
</b:loop>
</b:with>
</div>
<b:include name='quickedit'/>
</b:includable>
</b:widget>
- 它不是那么性感,您必须从特色 Post 小部件
中复制 html-结构
- 您必须根据需要更改
id='Blog2'
。
Mini Explanation to the filtering:
data:posts filter (p => p.labels any ( l => l.name == "label0" ))
data:posts: get all Posts
filter: is a lambda function, that will be called for all posts( to filter items ) and returns only "fitting" items
(p => ... ): is the outer function "construct"
p.labels: p
is the current post, labels
are the labels of the current post
any: is an other lambda function, that returns true
if one items "fits"
(l => l.name == "label0") ... inner function checking if the post has a label with the name label0
这里 link 一个很好的非官方参考网站:http://template-data.blogspot.co.at
标题基本上说明了一切。您是否知道如何调整 Blogger 的特色 Post 小工具,以便它可以只显示某个标签的最近 post,而不是显示我整个网站的最近 post?我只想要一个小部件,它可以显示我的一个标签中的最新 post(仅 1 个 post)。
这是我网站的 link。我所说的小工具在网站上称为随机 Post:http://newsotuniverse.blogspot.ca/
我还将为您 non-Blogger 用户提供一些网站代码,看看您是否可以解决问题:
<b:widget id='FeaturedPost1' locked='false' title='Random Post' type='FeaturedPost'>
<b:widget-settings>
<b:widget-setting name='showSnippet'>true</b:widget-setting>
<b:widget-setting name='showPostTitle'>true</b:widget-setting>
<b:widget-setting name='showFirstImage'>true</b:widget-setting>
<b:widget-setting name='useMostRecentPost'>true</b:widget-setting>
</b:widget-settings>
<b:includable id='main'>
<!-- Only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<b:include name='content'/>
<b:include name='quickedit'/>
</b:includable>
<b:includable id='content'>
<div class='post-summary'>
<b:if cond='data:showPostTitle and data:postTitle != ""'>
<h3><a expr:href='data:postUrl'><data:postTitle/></a></h3>
</b:if>
<b:if cond='data:showSnippet and data:postSummary != ""'>
<p>
<data:postSummary/>
</p>
</b:if>
<b:if cond='data:showFirstImage and data:postFirstImage != ""'>
<img class='image' expr:src='data:postFirstImage'/>
</b:if>
</div>
<style type='text/css'>
.image {
width: 100%;
}
</style>
</b:includable>
</b:widget>
如果有人能提供帮助,将不胜感激。提前致谢!
更新: 我更新了它现在过滤标签 label1
的帖子的代码。
我认为不可能,因为您无法访问标签 属性 来自 featured Post 数据元素, 但是 您可以用 Blog Widget 替换 FeaturedPost Widget,代码如下:
<b:widget id='Blog2' locked='true' title='FeaturedBlog' type='Blog' >
<b:includable id='main'>
<div class='post-summary'>
<b:with var="filteredData" value="data:posts filter (p => p.labels any ( l => l.name == "label0" ))">
<b:loop values='data:filteredData' var='post' index='index'>
<b:if cond='data:index == "0"' >
<h3><a expr:href='data:post.url'><data:post.title/></a></h3>
...
</b:if>
</b:loop>
</b:with>
</div>
<b:include name='quickedit'/>
</b:includable>
</b:widget>
- 它不是那么性感,您必须从特色 Post 小部件 中复制 html-结构
- 您必须根据需要更改
id='Blog2'
。
Mini Explanation to the filtering:
data:posts filter (p => p.labels any ( l => l.name == "label0" ))
data:posts: get all Posts
filter: is a lambda function, that will be called for all posts( to filter items ) and returns only "fitting" items
(p => ... ): is the outer function "construct" p.labels:p
is the current post,labels
are the labels of the current post any: is an other lambda function, that returnstrue
if one items "fits"
(l => l.name == "label0") ... inner function checking if the post has a label with the namelabel0
这里 link 一个很好的非官方参考网站:http://template-data.blogspot.co.at