编辑帖子计数器博客 [英] Editor post counter blogger

查看:111
本文介绍了编辑帖子计数器博客的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以显示编辑发布的帖子数量我在博客上有其他编辑,所以我想在每个编辑器下显示他发布的帖子数量。
like this image below



在此解决方案中,您需要对作者名称进行硬编码(这里是演示 Author1 Author2 )。

 < b:widget id ='Blog2'locked ='false'title ='Blogposts'type ='Blog '> 
< b:includable id ='main'>
< script>
< b:with var ='firstAuthorPosts'value ='data:posts filter(p =& gt; p.author.name ==& quot; Author1& quot;)'>
var author1 =< data:firstAuthorPosts.size /> ;;
< / b:with>
< b:with var ='secondAuthorPosts'value ='data:posts filter(p =& gt; p.author.name ==& quot; Author2& quot;)'>
var author2 =< data:secondAuthorPosts.size /> ;;
< / b:with>
window.addEventListener(load,function(){
//这里写这个信息到HTML
alert中(`Author 1 has:$ {author1} Posts and Author 2 has: $ {author2}文章`);
});
< / script>
< / b:includable>
< / b:widget>

要将Post添加到HTML中,您必须使用一些javascript,但是如何完成取决于您的模板生成的HTML。


这里使用lambda函数 filter 来自特定Auhtor的帖子,并获取大小后数组元数据的金额。

(由于它是两次作者)

window.addEvnetListener 添加事件,将数据写入警报(在您的情况下,然后是HTML-DOM )

有关使用的Blogger语法的更多详细信息,请访问:非官方文档



更新:
Javascript Details



  • < b:with var ='firstAuthorPosts' ...用名称 firstAuthorPosts

  • ... value ='...'> ... set是变量的值
  • >
  • data:posts ... blog-widget-variable for all posts。

  • 过滤器 ...是数组的lambda函数,它只返回元素,函数中的过去返回true

  • (p =& gt; p.author.name ==& quot; Author1& quot;) ...是函数,它将为数组中的每个元素执行,并且仅返回


  • $ b $所以< b:with var ='firstAuthorPosts'value ='data:posts filter(p =& gt; p。 author.name ==& quot; Author1& quot;)'> 创建一个变量并将该值设置为作者的所有文章,其名称为 Author1


    • < data:firstAuthorPosts.size /> ...返回数组中所有帖子的大小/数量 firstAuthorPosts



    所以 var author1 =< data:firstAuthorPosts.size />; 创建一个javascript变量,将被设置为作者的所有帖子的计数 Author1



    以下三行对于 Author2 $ b


    • 创建一个加载eventHandler,用于加载网站时

      窗口。 addEventHandler(load,function(){
      alert(`Author 1 has:$ {author1} Posts and Author 2 has:$ {author2} Posts`);





      $ 由于JavaScript变量 author1 author2 ,都是全局的,可以在事件函数中访问。



      这行只是显示,如何访问这些值:
      alert(`Author 1 has:$ {author1}文章和作者2 has :$ {author2} Posts`);



      它使用插值这就是为什么 $ {author1} $ {author2} 。 (文档到Javascript内插


      I wonder is it possible to show number of post posted by editor I have other editor with me on blogger so I want to show under every editor the number of post he posted. like this image below

      解决方案

      This could be a solution, you could add a Blog Widget and calculate the post like in this demo. In this solution you need to "hardcode" the Author Names(here for the Demo Author1 and Author2).

      <b:widget id='Blog2' locked='false' title='Blogposts' type='Blog' >
        <b:includable id='main'>
          <script>
            <b:with var='firstAuthorPosts' value='data:posts filter (p =&gt; p.author.name == &quot;Author1&quot;)'>
               var author1 = <data:firstAuthorPosts.size />;
             </b:with>    
             <b:with var='secondAuthorPosts' value='data:posts filter (p =&gt; p.author.name == &quot;Author2&quot;)'>
               var author2 = <data:secondAuthorPosts.size />;
             </b:with>    
             window.addEventListener("load", function(){
               // here write this info into the HTML
               alert(`Author 1 has: ${author1} Posts and Author 2 has: ${author2} Posts`);
             });
           </script>
        </b:includable>
      </b:widget>
      

      to add the Post to the HTML you would have to use some javascript, but how this is done depends on the HTML your template generates.

      Here a lambda function is used to filter posts from specific Auhtor and the get the amount with the size Post - Array Metadata.
      (It is done twice since it is for two Authors)
      the window.addEvnetListener Event is added, to write the Data into the alert (in your case then the HTML-DOM)

      More detailed information to the used Blogger Syntax can be found here: Unofficial Documentation

      Update: Javascript Details

      • <b:with var='firstAuthorPosts' ... creates a variable with the name firstAuthorPosts
      • ... value='...'> ... set's the value of the variable
      • data:posts ... blog-widget-variable for all posts.
      • filter ... is a lambda function for arrays, that returns only elements, where the past in function returns true
      • (p =&gt; p.author.name == &quot;Author1&quot;) ... is the function, that will be executed for each element in the array, and returns only

      So <b:with var='firstAuthorPosts' value='data:posts filter (p =&gt; p.author.name == &quot;Author1&quot;)'> creates a variable and sets the value to all posts of the author with the name Author1.

      • <data:firstAuthorPosts.size /> ... returns the size/count of all posts in the array firstAuthorPosts

      So var author1 = <data:firstAuthorPosts.size />; creates a javascript variable, that will be set to the count of all posts of the author Author1.

      The following three lines, are the same for the Author2

      • creates a load eventHandler, for when the Website is loaded
        window.addEventHandler("load", function(){ alert(`Author 1 has: ${author1} Posts and Author 2 has: ${author2} Posts`); });

      Since the Javascript variables author1 and author2, are global the can be accessed in the event function.

      This line is just to show, how to access the values: alert(`Author 1 has: ${author1} Posts and Author 2 has: ${author2} Posts`);

      It uses Interpolation thats why the ${author1} and ${author2}. (Documentation to Javascript interpolation)

      这篇关于编辑帖子计数器博客的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆