Thursday, January 6, 2011

How to show the published date for a SharePoint blog post in Content Query Web Part?

Questions:

What is the difference between the fields PubDate and PublishedDate in a SharePoint Blog Post content type?

How to display a SharePoint blog post's PublishedDate in Content Query Web Part ?

Explanation:

If you try to use Content Query Web Part hereafter referred to as CQWP to pull blog posts, you will notice that CQWP by default pulls the following fields:
  • Modified
  • Created
  • PubDate
It quite looks like the field "PubDate" refers to the date on which the blog post was published.
But in fact the "PubDate" field is the same as the field "Modified" except that it returns the date in a different format.

Resolution: 

The below is an example of how CQWP pulls data from the above 3 fields.
Modified="2011-01-06 12:53:18" 
Created="2011-01-06 12:49:52"
PubDate="Thu, 06 Jan 2011 17:53:18 GMT"

As you can notice above, the "Modified" and "PubDate" hold the same value and PubDate shows the data in the UK format.

In order to pull the actual date when the blog post was published, we will need to tweak the CQWP a little.

Export the CQWP and open it in your favorite editor like notepad.

The field that actually holds the date when a blog post is published is "PublishedDate".

We will need to let CQWP know that it needs to pull data for "PublishedDate" also.

Change the line
<property name="CommonViewFields" type="string" /> 
to
<property name="CommonViewFields" type="string">PublishedDate, DateTime;</property>

Import the web part back into web part gallery and add it back in.

The CQWP should now show the date when the blog post was published.

No comments:

Post a Comment