如何在Blogger帖子中创建带有图片的帖子列表

huangapple go评论121阅读模式
英文:

How to create list of posts in blogger post with images

问题

你好,我正在尝试创建类似分类的帖子列表,但我不知道如何创建带有图像和描述的列表,就像下面这样 -

我尝试创建,但数据的格式不正确,您可以在以下截图中看到 -

如何在Blogger帖子中创建带有图片的帖子列表

英文:

Hello I am trying to create list of post for similar categories but I am not getting how to create list with image and description like below -

I tried to create but formatting of data is not correct, you can see in following screen shot-

如何在Blogger帖子中创建带有图片的帖子列表

答案1

得分: 2

以下是您提供的HTML和JavaScript代码的翻译部分:

<style type='text/css'>
  .post {
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #EEE;
    overflow: hidden;
    font-family: tahoma;
  }
  .post-thumb {
    float: left;
    margin-right: 10px;
    border: 3px solid #fff;
    box-shadow: 0 0 1px #000;
  }
  .post-title {
    margin: 0 0 5px;
    line-height: 12px
  }
  .post-title a {
    font-size: 12px;
    color: #222;
    text-decoration: none
  }
  .post-title a:hover{
    color: coral;
    text-decoration: underline
  }
  .post-snippet{
    font-size: 12px;
    color: #666;
    margin: 5px 0;
  }
  .post-date {
    font-size: 12px;
    color: #999;
  }
</style>

<div id='posts'></div>

<script type='text/javascript'>
  function FeedPosts(jsondata){
    if(jsondata.feed.entry){
      var markup='';
      for( var p=0; p < jsondata.feed.entry.length; p++){
        var item      = jsondata.feed.entry[p],
            thumbnail = item['media$thumbnail'] ? item['media$thumbnail'].url.replace(/s72-c/, 'w150-h80-p') : '',
            title     = item.title.$t,
            link      = item.link.filter(function(l){ return l.rel == 'alternate' })[0].href,
            snippet   = item.content.$t.replace(/<\/?[^>]+(>|$)/g, '').substr(0, 80) + '...',
            date      = new Date(item.published.$t).toLocaleDateString();
        markup += '<div class="post">';
        markup += thumbnail ? '<img class="post-thumb" src="'+ thumbnail +'">' : '';
        markup += '<h2 class="post-title"><a href="'+ link +'">'+ title +'</a></h2>';
        markup += '<p class="post-snippet">'+ snippet +'</p>';
        markup += '<abbr class="post-date">'+ date +'</abbr>';
        markup += '</div>';
      }
      document.querySelector('#posts').innerHTML = markup;
    }
  }
</script>

这是您提供的代码的翻译部分,没有其他内容。

英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;style type=&#39;text/css&#39;&gt;/*&lt;![CDATA[*/
.post {
margin-bottom: 10px;
padding-bottom: 10px;
border-bottom: 1px solid #EEE;
overflow: hidden;
font-family: tahoma;
}
.post-thumb {
float: left;
margin-right: 10px;
border: 3px solid #fff;
box-shadow: 0 0 1px #000;
}
.post-title {
margin: 0 0 5px;
line-height: 12px
}
.post-title a {
font-size: 12px;
color: #222;
text-decoration: none
}
.post-title a:hover{
color: coral;
text-decoration: underline
}
.post-snippet{
font-size: 12px;
color: #666;
margin: 5px 0;
}
.post-date {
font-size: 12px;
color: #999;
}
/*]]&gt;*/&lt;/style&gt;
&lt;div id=&#39;posts&#39;&gt;&lt;/div&gt;
&lt;script type=&#39;text/javascript&#39;&gt;/*&lt;![CDATA[*/
function FeedPosts(jsondata){
if(jsondata.feed.entry){
var markup=&#39;&#39;;
for( var p=0; p &lt; jsondata.feed.entry.length; p++){
var item      = jsondata.feed.entry

, thumbnail = item[&#39;media$thumbnail&#39;] ? item[&#39;media$thumbnail&#39;].url.replace(/s72-c/, &#39;w150-h80-p&#39;) : &#39;&#39;, title = item.title.$t, link = item.link.filter(function(l){ return l.rel == &#39;alternate&#39; })[0].href, snippet = item.content.$t.replace(/&lt;\/?[^&gt;]+(&gt;|$)/g, &#39;&#39;).substr(0, 80) + &#39;...&#39;, date = new Date(item.published.$t).toLocaleDateString(); markup += &#39;&lt;div class=&quot;post&quot;&gt;&#39;; markup += thumbnail ? &#39;&lt;img class=&quot;post-thumb&quot; src=&quot;&#39;+ thumbnail +&#39;&quot;&gt;&#39; : &#39;&#39;; markup += &#39;&lt;h2 class=&quot;post-title&quot;&gt;&lt;a href=&quot;&#39;+ link +&#39;&quot;&gt;&#39;+ title +&#39;&lt;/a&gt;&lt;/h2&gt;&#39;; markup += &#39;&lt;p class=&quot;post-snippet&quot;&gt;&#39;+ snippet +&#39;&lt;/p&gt;&#39;; markup += &#39;&lt;abbr class=&quot;post-date&quot;&gt;&#39;+ date +&#39;&lt;/abbr&gt;&#39;; markup += &#39;&lt;/div&gt;&#39;; } document.querySelector(&#39;#posts&#39;).innerHTML = markup; } } /*]]&gt;*/&lt;/script&gt; &lt;!-- Replace &quot;6224600608277196834&quot; with your blog id --&gt; &lt;!-- OR Replace script source with &quot;/feeds/posts/default/-/Reactions?alt=json-in-script&amp;max-results=5&amp;callback=FeedPosts&quot; --&gt; &lt;!-- Replace &quot;Reactions&quot; with your category name --&gt; &lt;script src=&quot;https://www.blogger.com/feeds/6224600608277196834/posts/default/-/Reactions?alt=json-in-script&amp;max-results=5&amp;callback=FeedPosts&quot;&gt;&lt;/script&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2020年1月3日 22:58:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/59580758.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定