Matthew McDermott, MVP

General ramblings from a SharePoint MVP about SharePoint and Microsoft technologies related to collaboration, web content management and productivity.

Building a blog host, Part 3

In the previous post we created a web application to host our blog sites and built a Table of Contents with the TOC web part. We still have work to do to finish our home page. Our home page wireframe calls for a Recent Posts web part. In this post we'll cover the configuration of the web part and CSS to make it pretty. The summary of the steps are:

  • Create a "Recent Posts" rollup
  • Create a custom CSS for the site

Wireframe for home page

Create a "Recent Posts" roll-up

Our wireframe calls for a rollup of recent post activity in the middle of our home page. We will use a Content Query web part for this purpose. Most of the functionality that we require for the rollup will necessitate hand editing the web part.

  1. Place the home page in edit mode and click Add a Web Part to our Top Zone.
  2. Choose the Content Query web part and click Add.
  3. Edit the web part properties by choosing Edit | Modify shared web part.
  4. Change the settings as follows:
  5. Property

    Value

    Query

     

    Source

    Show items from all sites…

    List Type

    Posts

    Content Type

    List Content Types; Items; Include Child Types

    Presentation

     

    Feed

    Enable

    Feed Title

    Catapult Systems Blogs

    Feed Description

    Blogs about technology and miscellaneous ramblings from our employees

    Appearance

     

    Title

    Recent Posts

  6. Apply your changes and your web part should look like this:

Advanced web part configuration

We have gotten just about as far as we can with the out of the box configuration for our web part. We have yet to meet our requirements. The issues are:

  • The roll up does not show the post body, publish date and time or author
  • The posts are not ordered by Published date
  • The default styles do not suit our designers, so we need a custom cascading style sheet
  • The RSS feed for the web part does not include the post body or author
    1. To solve these deficiencies we need to use a combination of techniques. We will start by creating a new list item style and apply it to our web part. We will also add the additional fields required to display our post content.

      Customize the content query web part

      There are many great posts about how to customize the Content Query web part. I will not go into that level of detail here. I will use two new templates to complete our work. One will expose the fields available in the query. The other will roll up our posts.

      1. Open the blog host site in SharePoint Designer and navigate to the Style Library. Open the folder XSL Style Sheets. Check Out and Open the file ItemStyle.xsl.
      2. In code view locate the ending </xsl:stylesheet> tag. Immediately above the end tag insert the following code.
      3. <xsl:template name="CQFields" match="Row[@Style='CQFields']" mode="itemstyle">

             <xsl:for-each select="@*">

             P:<xsl:value-of select="name()" />

            </xsl:for-each>

        </xsl:template>

        <xsl:template name="BlogRecentPosts" match="Row[@Style='BlogRecentPosts']" mode="itemstyle">

        <xsl:variable name="SafeLinkUrl">

        <xsl:call-template name="OuterTemplate.GetSafeLink">

        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>

        </xsl:call-template>

        </xsl:variable>

        <xsl:variable name="DisplayTitle">

        <xsl:call-template name="OuterTemplate.GetTitle">

        <xsl:with-param name="Title" select="@Title"/>

        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>

        </xsl:call-template>

        </xsl:variable>

        <xsl:variable name="LinkTarget">

        <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>

        </xsl:variable>

        <div id="post">

            <div class="postTitle">

        <h2><a href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}">

        <xsl:value-of select="$DisplayTitle"/>

        </a></h2>

        </div>

        <div class="byLine"> posted @ <xsl:value-of select="msxsl:format-date(substring-before(@PublishedDate, ' '), 'MM/dd/yyy ')" />

            <xsl:value-of select="msxsl:format-time(substring-after(@PublishedDate, ' '), 'hh:mm tt')" /> by <xsl:value-of select="@Author" />

        </div>

        <div class="postBody">

            <xsl:value-of select="@Body" disable-output-escaping="yes" />

        </div>

        </div>

        </xsl:template>

        The first template, CQFields, renders the fields from the query so you can check your work. The second template is our post roll up template. This template requires our web part to deliver the fields Published Date, Body, and Author. We need to change our web part to make this template work.

      4. Return to the home page and choose Site Settings | Edit Page. From the web part Edit menu choose Export… Save the web part to your desktop.
      5. Open the web part file in Notepad and locate the line:
      6.     <property name="CommonViewFields" type="string"/>

        Change it to:

        <property name="CommonViewFields" type="string">Body, RichHTML;PublishedDate, DateTime</property>

      7. We also need to add the PublishedDate field to our sort order.

        Locate the line:

      8. <property name="AdditionalGroupAndSortFields" type="string" null="true" />

        And replace it with:

        <property name="AdditionalGroupAndSortFields" type="string" >PublishedDate,Published Date</property>

      9. Return to your home page and delete the Recent Posts web part. Click Add a web part and choose Advanced Web Part gallery and options from the bottom of the dialog.
      10. Click the Browse header and choose Import from the menu.
      11. Browse for your edited web part file and choose Open. Click Upload to upload your web part. Drag your recent posts web part into the top zone. The web part should look the same as before. Choose Edit | Modify shared web part. In the Presentation section click the drop down for Sort items by: and choose Published Date. Click Apply to save your changes.

         

      12. In step 4 we added additional fields to our web part. "CQFields" helps you see what fields are returned. In the web part Presentation section change the Item style to CQFields and apply your changes. Your web part should look like this:

        Notice our new fields Body and PublishedDate.

      13. Changing the Item style to BlogRecentPosts should yield the following look:

      14. Click OK to save your changes and your page should look like this:

      Create a custom CSS for the site

      Heather Solomon and Shane Peran have written extensively on writing CSS for SharePoint.

      1. Create a new css file in SharePoint Designer by browsing to the Style Library and right click and choose New | CSS.
      2. Rename the file blog.css.
      3. Open the file and insert the following code.
      4. div.postTitle h2

        {

            border-top: 1px #999999 solid;

            font-family: Verdana;

            line-height: 17pt;

            padding-top: 5px;

            padding-bottom: .1em;

            margin-bottom: 2px;

            margin-top: 0px;

        }

         

        .postBody

        {

            padding-bottom: 20px;

        }

         

        .byLine

        {

            color: maroon;

            font-family: Verdana;

            font-size: 7pt;

            padding-bottom: 10px;

            border-bottom: 1px maroon dotted;

            margin-bottom: 10px;

        }

         

        .ms-WPBody a:link

        {    

            color: black;    

            text-decoration: none;

        }

         

         

        .ms-WPBody a:visited

        {    

            color: #999999;    

            text-decoration: none;

        }

         

        .ms-WPBody a:visited:hover, .ms-WPBody a:link:hover

        {

            text-decoration: underline;

        }

         

        .level-description

        {

            font-weight: normal;

        }

        /* TOC web Part */

        #tocwp.toc-layout-main

        {

            padding-left: 5px;

        }

        .level-header

        {

            white-space:nowrap;

        }

        div.item

        {

            margin-left : 0px;

            padding-left: 5px;

        }

      5. Save the file and check it in.
      6. Return to the site and choose Site Actions | Site Settings | Modify All Site Settings
      7. Choose Master page and in the Alternate CSS URL section select the Specify a CSS file… radio button. Browse for the blog.css file we just created.

        Click OK to select the file.

      8. Your settings should look like this:

        Click OK to apply the styles.

      9. Your page should look like this:

         

      Summary

      Are we done? Maybe, maybe not…In our next post we'll customize the RSS output.

    Posted by Matthew McDermott on Tuesday, 20 Nov 2007 02:17
    12 Comments | Filed under: Community Kit for SharePoint, Office 2007, Web Publishing
    Bookmark this post with:        

    Comments

    On 24 Nov 2007 04:58, Jaap Steinvoorte said:

    Hi Matthew, Thanks for the fantastic posts, especially the ones about building a blog host. Can you explain step 5? Am I missing something? AdditionalFilterfields is a property which needs to be replaced with AdditionalGroupAndSortFields?

    On 24 Nov 2007 06:30, Matthew said:

    Thanks! You are right, it should read GroupAndSortFields, I fixed the post. Let me know how you get on. Send the URL if you can.

    On 24 Nov 2007 06:01, Jaap Steinvoorte said:

    Thanks Matthew :-) The url for the site collection is http://community.ada-ict.nl/ the blog I'm currently working on is http://community.ada-ict.nl/blogs/virtualgenerations but I got a major issue. Anonymous access is enabled, on the site collection and blog but I still get a login box on the blog :-( I hope to fix this in the next couple of days. Another issue is the presence of custom themes on my own blog. The other blogs don't have this themes. Everytime I select my own custom template for my blog, the other blogs also want to make use of this custom theme (which ain't present) and displayes an error. The last issue I'm working on is displaying recent comments (aggregation of comments of all blogs on the homepage of the site collection). For unknown reasons I can't select the comments list (only the posts list.) I'm discussing my issues with Vincent Rothwell on the CodePlex CKS site. By the way, I like your last post part 4 :D Thanks for sharing!

    On 25 Nov 2007 09:14, Matthew said:

    I feel your pain. Vincent has been amazing at helping me. For the anonymous issue I would start by disabling all CKS features and use the default master. This may help determine if it is a secure resource (like an image) or if it is CKS:EBE. He knows about the theme issue. To force a reset before he issues the fix you can use "http://url/blog/default.aspx?theme=default" or whatever your theme is. I am working on Part 5, Search.

    On 26 Nov 2007 12:55, Jaap Steinvoorte said:

    I've fixed the anonymous issue, twofold problem, first I had some things left in the web.config (from Windows Live Authentication. Second was the lockdown feature. Thanks for the tip about the default theme :-) I hardly can't wait for your next post about search. In the meanwhile I will investigate how the show the recent comments of all blogs.

    On 03 Dec 2007 06:45, Matthew said:

    I am glad you got it fixed! Anonymous issues can be a bear. For your comments I would use a similar strategy to the recent posts, Content Query Web Part. The only trick might be making the URL direct the visitor to the linked post.

    On 31 Dec 2007 03:48, Jaap Steinvoorte said:

    Hi Matthew, Best wishes for 2008! :-) Do you have any idea how I can bypass copyutil.aspx? It's used in the GetSafeLink property. For some dark reasons it's not allowed when anonymous access is enabled and Forms Bases Authentication is activated.

    On 31 Dec 2007 08:28, Matthew said:

    Jaap, Happy New Year to you! Where are you seeing the copyutil.aspx page being applied?

    On 20 Jan 2008 01:51, Mike Geyer said:

    Matthew, thanks for your help in getting a blog host up and running. I was also running into the problems with CopyUtil.aspx and anonymous users. I created a quick blog entry that describes how to create your own Item Style for linking to blog entries (notice, the example is 'hard coded' for links to blog posts): Content Query Web Part (CQWP) with Anonymous Access http://blogs.edork.com/MikeGeyer/Lists/Posts/Post.aspx?ID=20 I hope this helps and thanks again for your blog.

    On 30 Jan 2008 02:34, Jaap Steinvoorte said:

    Hi Matthew, sorry for responding a little late, too much information overload :-) I've forms based authentication installed and configured. The recent posts web part lists the recent articles of all blogs, but there's also an rss feed enabled. Clicking the link of a particular feeditem displays the copyutil.aspx and redirects the reader to the login page. http://community.ada-ict.nl on the front page shows the web part with the rss feed. The little icon is the SharePoint feed, the big one is the rss on feedburner. I'm experiencing quite strange behavior in FireFox. In the feed the Titles aren't hyperlinks anymore. I think the reason copyutil is issued is because somewhere something isn't published and approved. Now for a couple of days I'm trying to find out where it is. When checking for unpublished items SharePoint tells me that all external hyperlinks in de articles (on the main page) are not published....??? Quite strange. Anyway, I think I need to read the article written by Mike Geyer.

    On 20 May 2008 05:39, Aria Zanganeh said:

    Hi Matthew, I have a question on development of our webpart. I am developing new webpart and we are using EditorPart. When the user is in "Edit mode", on right hand side he see the editpart and application configuration. I want to group the webpart properties that shown as textbox grouped with our editorpart not like now separately. I want to know how can I don this. Thanks for your attention, Rez Zanganeh

    On 20 May 2008 07:13, Matthew McDermott said:

    Rez, I don't understand your question. You should seek support from the Community Forums at: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1203&SiteID=1

    Leave a comment

    Name (required)

    Url

    Email

    Comments

    Complete this section to post your comment