Showing posts with label SEO. Show all posts
Showing posts with label SEO. Show all posts

Wednesday, 4 March 2009

Adding Metadata to a MOSS 2007 Publishing Portal pt2

Add three columns to the Content Type that you use for WCM. In this example I've used PageTitle, PageDescription and PageKeywords.

Add the assembly to the Master Page and reference the MetaData dll
<%@ Register TagPrefix="metaControl" Namespace="MetaData.Render" Assembly="MetaData.Render, Version=1.0.0.0, Culture=neutral, PublicKeyToken=198d2f392e054e3e" %>

Example: In the head
<metaControl:SharePointMetaTag runat="server" ID="metaTag1" MetaName="DESCRIPTION" MetaAttributeName="Content" PublishingPagePropertyName="PageDescription" DefaultAttributeContent=""/>


The DefaultAttributeContent is where the editor has not completed the field as we've made them non manditory

namespace MetaData.Render
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
// using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

///
/// A webpart to render MetaData information onto a published page
///

[ParseChildren(false), ToolboxData("<{0}:MetaTag runat=\"server\" name=\"\"> "), PersistChildren(true),
AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal),
DefaultProperty("Name")]
public class MetaData : WebControl
{
///
/// Name to render out
///

private string name;

///
/// Initializes a new instance of the MetaData class.
///

public MetaData() : base(HtmlTextWriterTag.Meta)
{
}

///
/// Gets or sets the Tag name to render out
///

[Bindable(true), Category("Appearance"), DefaultValue(""), Description("Sets the MetaTag's name attribute.")]
public string Name
{
get { return this.name; }
set { this.name = value; }
}

///
/// Render the control
///

/// Render this writer
protected override void Render(HtmlTextWriter writer)
{
// Render control only if there is a tagname specified
if (!this.name.Equals(string.Empty))
{
base.Render(writer);
}
}

///
/// Add attributes to Render
///

/// The writer to add the attributes to
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
// Write the name attribute
writer.AddAttribute("name", this.name);

// Write the value attribute
StringWriter sw = new StringWriter();
base.RenderContents(new HtmlTextWriter(sw));
writer.AddAttribute("value", sw.ToString());
}

///
/// Render the content out
///

/// The writer to be rendered
protected override void RenderContents(HtmlTextWriter writer)
{
// this control does not render any contents
}
}
}

Thursday, 26 February 2009

Adding Metadata to a MOSS 2007 Publishing Portal

I found a way of adding MetaData to each page within a public facing website. There are still discussions on whether it is of any value, as some search engines don't always read it, to change the description and keywords.

In the Content Type(s) that the pages use add three fields - one for page title that will appear in the browser and will not affect the title used for the .aspx and in menus, one for the description as for some reason the description added when the page is created is not used (though I don't know it is crawled and returned in search results) and keywords.

I didn't add these fields to the page layout as there are lots of pages for our Marketing department, who own the content, to redo.

I'll post up the rest of the code tomorrow as I don't have the code at home.