问题
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>
The only change I made was to change the conditional Home to the static page.
回答1:
On single post pages and static pages, you can get only one post data via data:posts
loop.
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>
来源:https://stackoverflow.com/questions/58925862/filters-blogger-posts-on-a-specific-page