Filters Blogger posts on a specific page

不羁岁月 提交于 2020-01-25 06:43:32

问题


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=&gt; p.labels any (l=&gt; l.name == &quot; TAG &quot;)) 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 != &quot;item&quot;'>
<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 != &quot;static_page&quot;'>
<b:if cond='data:blog.pageType != &quot;item&quot;'>
<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='&quot;post-body-&quot; + data:post.id'>

<b:if cond='data:blog.pageType == &quot;item&quot;'>

</b:if>

<b:if cond='data:blog.pageType != &quot;static_page&quot;'>
<b:if cond='data:blog.pageType != &quot;item&quot;'>
   <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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!