出于搜索引擎优化的目的,我想复制此博客文章设计this website 我要复制的具体部分是div =" enter-posts"其中包含帖子的标题,作者,日期,标签
我试着把标签放在:
<div class='author-profile' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'>
<meta expr:content='data:post.authorProfileUrl' itemprop='url'/>
<b:if cond='data:post.authorPhoto.url'><a expr:href='data:post.authorProfileUrl' itemprop='url'>
<div class='auhtor-image'><img expr:src='data:post.authorPhoto.url' itemprop='image'/></div></a></b:if>
<div><span class='author-about'>About </span><a class='g-profile' expr:href='data:post.authorProfileUrl' rel='author' title='author profile'><span itemprop='name'><data:post.author/></span></a></div><p class='description' itemprop='description'><data:post.authorAboutMe/></p></div>
for author等等我要添加的其他元素但问题是:
当我在标题之前或帖子结尾处将这些标签放在帖子正文中时,没有显示任何内容,但是它们正常显示。我该怎么办?
答案 0 :(得分:0)
您无法在帖子正文或外部窗口小部件中使用HttpContext.Current.AcceptWebSocketRequest(Function() Tasks.Task.FromResult(New ChatWebSocketHandler()))
等博客数据标记。请阅读Layouts Data Tags
答案 1 :(得分:0)
尽管这是一篇过时的文章,但我可以为那些寻求答案的人发表一些澄清。事实是,博客没有提供data:post.authorPhoto.url
。
大多数模板编写者都从/feeds/posts/default
获取数据,并解析JSON并在页面加载后更新HTML。然后他们混淆了js代码,使新手认为这都是从博主那里获取的。除了那次获取之外,谁知道还获取了什么。
例如,对于上述博客,您可以从http://www.th3professional.com/feeds/posts/default?alt=json-in-script
获取JSON。我的实现
-
var HttpClient = function() {
this.get = function(aUrl, aCallback) {
var anHttpRequest = new XMLHttpRequest();
anHttpRequest.onreadystatechange = function() {
if (anHttpRequest.readyState == 4 && anHttpRequest.status == 200)
aCallback(anHttpRequest.responseText);
}
anHttpRequest.open("GET", "https://cors-anywhere.herokuapp.com/"+aUrl, true);
anHttpRequest.send(null);
}
}
$(document).ready(function($){
// This is one way to get post id, other ways are possible too
var post_id = $("div[itemprop='articleBody']").attr('id');
post_id = post_id.match(/.*post-body-(\d+).*/);
post_id = ((post_id!==null && post_id.length>0) ? post_id[1] : null);
if(post_id!==null) {
$.ajax({
url: "/feeds/posts/default/"+post_id+"?alt=json-in-script",
type: 'get',
dataType: "jsonp",
success: function(data) {
var image = ((data.entry.author[0]["gd$image"].src!==null) ? data.entry.author[0]["gd$image"].src : false);
if(image!=false) { //site correct class here
$('.author-image').attr('src', image);
}
var description = false;
var client = new HttpClient();
client.get((data.entry.author[0].uri["$t"]).replace("http", "https"), function(response) {
var doc = document.documentElement.cloneNode();
doc.innerHTML = response;
$content = $(doc.querySelectorAll('tr'));
for(var lk=0; lk<$content.find('th.item-key').length; lk++) {
if($content.find('th.item-key')[lk].innerText=="Introduction" && $content[lk].querySelectorAll('td')[0]!==null) {
description = $content[lk].querySelectorAll('td')[0].textContent;
break;
}
}
if(description!=false) { //site correct class here
$('.description').text(description);
}
});
}
}); } });