How to store the URL's and Titles of a list of posts under same label into a String array in Blogger

穿精又带淫゛_ 提交于 2019-11-28 11:19:36

问题


The question I have is, how to store the URL's and Titles of the posts under the one and the same label into a String array.

Suppose I have a number of posts under the label Action http://rawmangaread.blogspot.in/search/label/Action/
And supposedly the posts Titles and URL's under that Category or Label are :

Post 1:

Title : Konjiki no WordMaster Chapter 1
URL : http://rawmangaread.blogspot.in/2017/03/konjiki-no-wordmaster-chapter-1.html

Post 2:

Title : Konjiki no WordMaster Chapter 2
URL : http://rawmangaread.blogspot.in/2017/03/konjiki-no-wordmaster-chapter-2.html

Post 3:

Title : Dungeon Seeker Chapter 1
URL : http://rawmangaread.blogspot.in/2017/03/dungeon-seeker-chapter-1-raw-manga.html

and some others... I want 2 arrays like var pTitle and var pURL and I want it to store like this

pTitle[0]=Konjiki no WordMaster Chapter 1  
pTitle[1]=Konjiki no WordMaster Chapter 2  
pTitle[2]=Dungeon Seeker Chapter 1  

pURL[0]=http://rawmangaread.blogspot.in/2017/03/konjiki-no-wordmaster-chapter-1.html  
pURL[1]=http://rawmangaread.blogspot.in/2017/03/konjiki-no-wordmaster-chapter-2.html  
pURL[2]=http://rawmangaread.blogspot.in/2017/03/dungeon-seeker-chapter-1-raw-manga.html

Please Help by providing a Code :D


回答1:


The following code should be able to achieve what you require -

<b:if cond='data:blog.searchLabel'>
  <script>
    var URLArray = <b:eval expr='data:posts map (post =&gt; post.url)'/>;
    var TitleArray = <b:eval expr='data:posts map (post =&gt; post.title)'/>;
  </script>
</b:if>

The b:if condition only loads this code on Label pages. Also, to make it work, place this inside the Blog gadget (Add it inside the <b:includable id='main' var='top'> tag. Don't include it inside the b:loop tag for posts or it will get repeated multiple times on a page)



来源:https://stackoverflow.com/questions/43017303/how-to-store-the-urls-and-titles-of-a-list-of-posts-under-same-label-into-a-str

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