Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
662 views
in Technique[技术] by (71.8m points)

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

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 URL And supposedly the posts Titles and URL's under that Category or Label are :

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

pTitle[0]=Comic 1 Chapter 1  
pTitle[1]=Comic 1 Chapter 2  
pTitle[2]=Comic 2 Chapter 1  

pURL[0]=url 
pURL[1]=url  
pURL[2]=url

Please Help by providing a Code :D

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...