问题
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.htmlPost 2:
Title : Konjiki no WordMaster Chapter 2
URL : http://rawmangaread.blogspot.in/2017/03/konjiki-no-wordmaster-chapter-2.htmlPost 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 => post.url)'/>;
var TitleArray = <b:eval expr='data:posts map (post => 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