ニュース記事のメタ タグは、[いいね] ボタンを表示しているページにある必要はありません。ニュース記事は、Like ボタンの URL パラメータにリストされたページのメタ タグから生成されます。
ここに例があります。-
この Repeater は、カスタマイズされた Like ボタンを使用して、データベースから製品のリストを動的に生成します。
<asp:Repeater ID="_RPT_Product" runat="server">
<HeaderTemplate><h3>Products</h3><ul class="bulleted-list"></HeaderTemplate>
<ItemTemplate><li><a href="http://www.yourdomainname.com/Product.aspx?ID=<%#((Product)Container.DataItem).ProductID %>" target="_blank"><%# Utilities.ScrubText(((Product)Container.DataItem).ProductName) %></a>
</li>
<div style="padding-top:10px;">
<iframe
src="https://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.yourdomainname.com/Product.aspx%3FID%3D<%#((Product)Container.DataItem).ProductID %>%26x%3D1&send=false&layout=button_count&width=88&show_faces=false&action=like&colorscheme=light&font&height=23"
scrolling="no" frameborder="0"
style="border:none; overflow:hidden; width:88px; height:23px;"
allowTransparency="true">
</iframe></div><br />
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
これは、製品データベースからメタ タグを動的にレンダリングする別の製品ページのコード ビハインドです。
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Get the product meta content from the ID URL parameter.
string productName = "";
string productImageURL = "";
string productDescription = "";
int productID = 0;
if (Request.QueryString["ID"] != null)
{
productID = Convert.ToInt32(Request.QueryString["ID"]);
}
if (Request.QueryString["ID"] != null)
{
using (ProductDatabaseDataContext db = new ProductDatabaseDataContext(Config.ConnectionStrings.ProductDatabase))
{
Product select = new Product();
select = db.Products.FirstOrDefault(p =>
p.ProductID == Convert.ToInt32(Request.QueryString["ID"]));
productName = select.ProductName;
productImageURL = select.ProductImageURL;
productDescription = select.ProductDescription;
}
}
// Dynamically generate Open Graph Meta Tags for each Product:
HtmlMeta _metaTitle = new HtmlMeta();
_metaTitle.Name = "og:title";
_metaTitle.Content = "Product: " + productName;
this.Header.Controls.Add(_metaTitle);
HtmlMeta _metaURL = new HtmlMeta();
_metaURL.Name = "og:url";
_metaURL.Content = "http://www.yourdomainname.com/Product.aspx?ID=" + Convert.ToString(productID);
this.Header.Controls.Add(_metaURL);
HtmlMeta _metaImage = new HtmlMeta();
_metaImage.Name = "og:image";
_metaImage.Content = Convert.ToString(productImageURL);
this.Header.Controls.Add(_metaImage);
HtmlMeta _metaDescription = new HtmlMeta();
_metaDescription.Name = "og:description";
_metaDescription.Content = Convert.ToString(productDescription);
this.Header.Controls.Add(_metaDescription);
}
}
1 つの URL に結び付けることができるメタ コンテンツ属性のセットは 1 つだけであるため、すべての [いいね!] ボタンには一意の URL パラメーターが必要です。これは、個別の Product.aspx ページに一意の ID パラメーターを設定することで実現できます。すべての製品ニュース ストーリーを 1 つのマスター リスト ページにリンクさせたい場合は、各製品の "og:url" メタ タグを同じにすることができます。