Difference between revisions of "How do I add meta tags?"

From AbleCommerce Wiki
Jump to: navigation, search
(New page: '''Problem''' How do i add meta tags on the static pages? '''Solution''' In order to add the meta tags easily to AC7.0 first we must customized and provide some GUI support for this fea...)
 
Line 5: Line 5:
 
'''Solution'''
 
'''Solution'''
  
In order to add the meta tags easily to AC7.0 first we must customized and provide some GUI support for this feature. For this purpose create a page '''MetaTags.aspx'''and its contents would be
+
The meta tags addition is not that straight. Bellow is a detailed overview that how to add these tags
 +
in AbleCommerce 7.0
 +
 
 +
<code>
 +
<pre>
 +
1. Be logged in as an admin that can edit pages
 +
2. go to the store page you want to set meta tags for
 +
3. toggle "edit page" in footer
 +
4. observe what is being used as "active layout"
 +
5. go to admin
 +
6. go to website _> content and layout
 +
7. locate the layout scriptet in use for the page
 +
8. click the copy button, you will be taken to the edit screen for your copy
 +
9. enter a name that is appropriate (e.g. HOME PAGE)
 +
10. In the header field, enter your meta tags...
 +
Code:
 +
<META NAME="Description" CONTENT="Your descriptive sentence or two goes here.">
 +
 
 +
11. Click Save to create the new page layout (including meta header)
 +
12. Return to the store page
 +
13. toggle "edit page" in footer
 +
14. set the layout to the one you created
 +
15. Click OK to set the page to your new layout
 +
</pre>
 +
</code>
 +
 
 +
As you see that above is a lengthy process. Thanks GOD their is anther option available and that is the Product class's HtmlHead field. All we have to do is create some interface for this field so that user can input meta tags some where.
 +
 
 +
In order to add the meta tags easily to AC7.0 first we must customized and provide some GUI support for this feature. For this purpose create a page '''MetaTags.aspx''' in '''Website\Admin\Products''' folder and its contents would be
 
<code>
 
<code>
 
<pre>
 
<pre>
Line 133: Line 161:
 
</pre>
 
</pre>
 
</code>
 
</code>
 
+
Now edit the '''Website\Admin\Products\ProductMenu.ascx''' file and add the link for this newly created page so that you can access this feature on EditProduct page.
<code>
+
<pre>
+
 
+
 
+
</pre>
+
</code>
+

Revision as of 06:55, 8 September 2008

Problem

How do i add meta tags on the static pages?

Solution

The meta tags addition is not that straight. Bellow is a detailed overview that how to add these tags in AbleCommerce 7.0

1. Be logged in as an admin that can edit pages
2. go to the store page you want to set meta tags for
3. toggle "edit page" in footer
4. observe what is being used as "active layout"
5. go to admin
6. go to website _> content and layout
7. locate the layout scriptet in use for the page
8. click the copy button, you will be taken to the edit screen for your copy
9. enter a name that is appropriate (e.g. HOME PAGE)
10. In the header field, enter your meta tags...
Code:
<META NAME="Description" CONTENT="Your descriptive sentence or two goes here.">

11. Click Save to create the new page layout (including meta header)
12. Return to the store page
13. toggle "edit page" in footer
14. set the layout to the one you created
15. Click OK to set the page to your new layout

As you see that above is a lengthy process. Thanks GOD their is anther option available and that is the Product class's HtmlHead field. All we have to do is create some interface for this field so that user can input meta tags some where.

In order to add the meta tags easily to AC7.0 first we must customized and provide some GUI support for this feature. For this purpose create a page MetaTags.aspx in Website\Admin\Products folder and its contents would be

<%@ Page Language="C#" MasterPageFile="Product.master" Title="Meta Tags" Inherits="CommerceBuilder.Web.UI.AbleCommerceAdminPage" %>
<%@ Register Assembly="CommerceBuilder.Web" Namespace="CommerceBuilder.Web.UI.WebControls" TagPrefix="cb" %>
<%@ Register Assembly="ComponentArt.Web.UI" Namespace="ComponentArt.Web.UI" TagPrefix="ComponentArt" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">

    int _ProductId;
    Product _Product;
    
    protected void Page_Load()
    {
        if (!Page.IsPostBack)
        {
            Populate();
        }
    }

    protected void SaveHeader(Object s, EventArgs e)
    {
        _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
        _Product = ProductDataSource.Load(_ProductId);
        _Product.HtmlHead = HTMLBox.Text;
        _Product.Save();
        Populate();
    }

    protected void RegenerateHeader(Object s, EventArgs e)
    {
        String Header = "";
        Header += "<title>" + PageTitle.Text + "</title>" + Environment.NewLine;
        Header += "<meta name='description' content='" + MetaDescription.Text + "'>" + Environment.NewLine;
        Header += "<meta name='keywords' content='" + MetaKeywords.Text + "'>" + Environment.NewLine;
        HTMLBox.Text = Header;
    }

    protected void Populate()
    {
        _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
        _Product = ProductDataSource.Load(_ProductId);
        int titleStart;
        int titleEnd;
        int descStart;
        int descEnd;
        int keyStart;
        int keyEnd;
        String Header = "";
        String TitleTag = "";
        String MetaDesc = "";
        String MetaKey = "";
        Header = _Product.HtmlHead;
        if (Header.Length > 0)
        {
            titleStart = Header.IndexOf("<title>") + 7;
            titleEnd = Header.IndexOf("</title>");
            if (titleStart > 0 && titleEnd > 0 && titleEnd > titleStart)
                TitleTag = Header.Substring(titleStart, titleEnd - titleStart);
            descStart = Header.IndexOf("<meta name='description' content='") + 34;
            descEnd = Header.IndexOf("'>", descStart);
            if (descStart > 0 && descEnd > 0 && descEnd > descStart)
                MetaDesc = Header.Substring(descStart, descEnd - descStart);
            keyStart = Header.IndexOf("<meta name='keywords' content='") + 31;
            keyEnd = Header.IndexOf("'>", keyStart);
            if (keyStart > 0 && keyEnd > 0 && keyEnd > keyStart)
                MetaKey = Header.Substring(keyStart, keyEnd - keyStart);
        }
        HTMLBox.Text = Header;
        PageTitle.Text = TitleTag;
        MetaDescription.Text = MetaDesc;
        MetaKeywords.Text = MetaKey; 
    }
    
    

</script>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">
<div class="pageHeader">
    <div class="caption">
        <h1><asp:Localize ID="Localize1" runat="server" Text="Meta Tags"></asp:Localize></h1>
    </div>
<div class="Content" style="padding:40px; border:1px solid blue;">
    <table width="90%">
        <tr>
            <td width="20%">
                <asp:Label Font-Bold="true" ID="HTMLBoxLabel" runat="server" Text="HTML Header"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="HTMLBox" TextMode="MultiLine" runat="server" Columns="100" Height="100"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="20%">
                <asp:Label Font-Bold="true" ID="TitleLabel" runat="server" Text="Title Tags"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="PageTitle" runat="server" Columns="100" Height="20"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="20%">
                <asp:Label Font-Bold="true" ID="MetaDescriptionLabel" runat="server" Text="Meta Description"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="MetaDescription" runat="server" Columns="100" Height="20"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="20%">
                <asp:Label Font-Bold="true" ID="MetaKeywordsLabel" runat="server" Text="Meta Keywords"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="MetaKeywords" runat="server" Columns="100" Height="20"></asp:TextBox>
            </td>
        </tr>
    </table>
    <center>
        <asp:Button ID="Regenerate" Text="Regenerate Header" runat="server" OnClick="RegenerateHeader" />
          
        <asp:Button ID="SaveIt" Text="Save" runat="server" OnClick="SaveHeader" />
    </center>
</div>
  
</asp:Content>

Now edit the Website\Admin\Products\ProductMenu.ascx file and add the link for this newly created page so that you can access this feature on EditProduct page.