过滤特定页面上的Blogger帖子 [英] Filters Blogger posts on a specific page
问题描述
我再次来找你.看看我的代码.
I come to you again. See my code.
我正在尝试从特定标签过滤文章,以使它们仅显示在静态页面上.
I am trying to filter articles from a particular tag so that they only appear on a static page.
我只能在主页上这样做.
I can do this only on the homepage.
当我尝试在特定页面上执行相同操作时,没有任何显示.
When I try to do the same on a specific page nothing appears.
这是主页上可用的代码.
Here is the code that works on the homepage.
<b:if cond='data:blog.pageType == "static_page"'>
<b:section id='posts-noticias'>
<b:widget id='Blog2' locked='true' title='Blog Archive' type='Blog'>
<b:includable id='main' var='top'>
<b:if cond='data:blog.pageType == "static_page"'>
<b:loop values='data:posts where (p=> p.labels any (l=> l.name == " TAG ")) take 6' var='post'>
<b:include data='post' name='printPosts'/>
</b:loop>
<b:else/>
<b:include data='post' name='printPosts'/>
</b:if>
</b:includable>
<b:includable id='printPosts' var='post'>
<div class='post hentry' style="background-color: #ffff00; border-width:1px; border-style: solid; border-color: #000000; height: 200px">
<b:if cond='data:blog.pageType != "item"'>
<b:if cond='data:post.title'>
<h2 class='post-title entry-title'>
<b:if cond='data:post.link'>
<a expr:href='data:post.link'><data:post.title/></a>
<b:else/>
<b:if cond='data:post.url'>
<a expr:href='data:post.url'><data:post.title/></a>
<b:else/>
<data:post.title/>
</b:if>
</b:if>
</h2>
</b:if>
<b:else/>
</b:if>
<b:if cond='data:blog.pageType != "static_page"'>
<b:if cond='data:blog.pageType != "item"'>
<div class='cutter'>
<b:if cond='data:post.isFirstPost'>
</b:if>
<a expr:alt='data:post.title' expr:href='data:post.url' expr:title='data:post.title'>
<div class='Image thumb'>
<img expr:alt='data:post.title' expr:src='resizeImage(data:post.firstImageUrl, 200, "150:70")' expr:title='data:post.title'/>
</div>
</a>
</div>
</b:if></b:if>
<div class='post-body entry-content' expr:id='"post-body-" + data:post.id'>
<b:if cond='data:blog.pageType == "item"'>
</b:if>
<b:if cond='data:blog.pageType != "static_page"'>
<b:if cond='data:blog.pageType != "item"'>
<b:eval expr='snippet(data:post.body, {length: 100, links: false})'/>
</b:if>
</b:if>
</div>
</div>
</b:includable>
</b:widget>
</b:section>
</b:if>
我所做的唯一更改是将条件Home更改为静态页面.
The only change I made was to change the conditional Home to the static page.
推荐答案
在单个帖子页面和静态页面上,通过data:posts
循环只能获取一个帖子数据.
On single post pages and static pages, you can get only one post data via data:posts
loop.
您可以做的是将Blogger JSON供稿与JavaScript结合使用,以获取所需的内容.
What you can do is to use Blogger JSON feed with JavaScript to get what you want.
例如:此代码获取博客上的前六个标题.
For example: this code fetches the first six titles on your blog.
<div id="foo"></div>
<script>
//<![CDATA[
fetch('/feeds/posts/summary?alt=json&max-results=6')
.then(response => response.json()).then(json => {
let posts = json.feed.entry.map(e => `<h2>${e.title.$t}</h2>`);
document.getElementById('foo').innerHTML = posts.join('');
});
//]]>
</script>
这篇关于过滤特定页面上的Blogger帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!