【问题标题】:show blog Author , title , label and time in a specific div blogger在特定 div 博主中显示博客作者、标题、标签和时间
【发布时间】:2016-10-14 16:53:36
【问题描述】:

出于 SEO 的目的,我想复制这篇博文设计this website 我要复制的特定部分是 id="enter-posts" 的 div,其中包含帖子的标题、作者、日期、标签

我尝试添加如下标签:

<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>

对于我要添加的其他元素的作者等,但问题是:

什么都没有显示,但是当我把这些标签放在帖子正文中的标题之前或帖子的末尾时,它们会正常显示。我该怎么办?

【问题讨论】:

    标签: tags label title blogger author


    【解决方案1】:

    虽然这是一个旧帖子,但我可以为那些寻找答案的人发布一些澄清。事实上,没有博主提供的data:post.authorPhoto.url

    大多数模板编写者从 /feeds/posts/default 获取数据并解析 JSON 并在页面加载后更新 HTML。然后他们混淆了 js 代码,让新来的人认为这都是从博主那里获取的。除了那个抓取之外,谁知道还抓取了什么。

    比如上面的博客,可以从http://www.th3professional.com/feeds/posts/default?alt=json-in-script获取JSON

    我的实现

    1. 直接从 Feed 中获取图片
    2. 作者描述取自用户配置文件的“简介”部分。因为那是 CORS,所以我为此目的使用了 CORS 代理 (https://github.com/Rob--W/cors-anywhere/)。

    -

    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);
                     }
                });
            }
        }); } });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-11
      • 2018-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多