问题
I am starting to make blogger templates from scratch and i am making a research about best SEO metadata for each post. I think the most logical way to use meta name=keywords is to use post labels as keywords but i don't understand why i cant retrieve the data and display it in the meta section as i can with the data from description. for expample:
<b:if cond='data:blog.pageType != "error_page"'>
<meta expr:content='data:blog.metaDescription' name='description'/>
</b:if>
puts the data comming from blog.metaDescription as content for meta description, but when i want to use:
<meta expr:content='data:post.labels.name' name='keywords' />
Which should be the data retrieved from the post labels, it doesn't display anything... as if there is no such data... i wonder why please help ... i am going mad with this, i tried a lot of stuff and i cant accomplish to use post labels as meta keywords.
Best Regards
回答1:
You can only retrieve post labels inside Blog Posts widget <b:widget type='Blog' ...>
and that is through a loop tag like the following
<b:loop values='data:post.labels' var='label'>
<data:label.name/>
</b:loop>
Or you can also use a lambda expression
<b:eval expr='data:post.labels map (label => label.name)'/>
回答2:
The following code should work -
<meta content="<b:loop values='data:post.labels' var='label'><data:label.name/><b:if cond='not data:label.isLast'>,</b:if></b:loop>" name='keywords'/>
But the shortcoming being that it will only work in the post area (present inside the <body>
tag) and not in the <head>
region
来源:https://stackoverflow.com/questions/43824583/use-blogger-post-labels-as-meta-data-keywords