2011-04-19 51 views
2

當我喜歡我們網站(www.potatopro.com)上的一篇文章,上面有Facebook和Facebook分享按鈕時,錯誤的網站數據正在被抓取。 您無法更改圖片,或者在其他情況下,facebook會取得導航而不是內容。添加Facebook打開圖表協議元標記到分享點

據我的理解,我必須在我們的網站上實現Facebook的開放圖協議元標籤。但我該如何做一個基於SharePoint的網站?!請指教!

回答

3

您可以將Web部件添加到頁面正在使用的頁面佈局中。在webpart中添加一個函數,用於查找頁面上的標題,內容和圖像,並將元標記寫入該頁面正在使用的主頁面。這裏是一個功能的例子...

protected override void Render(HtmlTextWriter writer) 
    { 
     if (SPContext.Current != null && SPContext.Current.ListItem != null) 
     { 
      SPListItem item = SPContext.Current.ListItem; 
      var title = item["Title"]; 
      if (title != null) 
      { 
       writer.WriteBeginTag("meta"); 
       writer.WriteAttribute("property", "og:title"); 
       writer.WriteAttribute("content", title.ToString()); 
       writer.WriteEndTag("meta"); 
      } 
      var pageContent = item["PublishingPageContent"]; 
      if (pageContent != null) 
      { 
       string strippedPageContent = Regex.Replace(pageContent.ToString(), @"<(.|\n)*?>", string.Empty); 
        writer.WriteBeginTag("meta"); 
      writer.WriteAttribute("property", "og:description"); 
      writer.WriteAttribute("content", strippedPageContent); 
      writer.WriteEndTag("meta"); 
      } 

      var pageImage = item["PublishingPageImage"]; 
      if (pageImage != null) 
      { 
       ImageFieldValue pageImageValue = pageImage as ImageFieldValue; 
       if (pageImageValue != null) 
       { 
        var url = pageImageValue.ImageUrl; 
        writer.WriteBeginTag("meta"); 
        writer.WriteAttribute("property", "og:image"); 
        writer.WriteAttribute("content", url); 
        writer.WriteEndTag("meta"); 
       } 
      } 

     } 
    }