Showing blog posts on other site
I use the blog feature of SharePoint 2010 quite often. It provides a good way of publishing new news items in your organisation. But sometimes, there’s the requirement of displaying your blog messages on a different site, for exmaple the landingpage of your intranet. Well there are a few ways of accomplishing this, but usually that means that you loose the look and feel of the default blog page. Here’s a way of doing this without loosing the markup!
Perform the following tasks:
- Open up the site on which you want to display the blog items in SharePoint Designer
- Go to “Data Sources” and add a new SOAP WebService datasource
- Provide the link to the ListItems webservice on your blog. This link will look like http://sharepoint/site/blog/_vti_bin/lists.asmx
- Provide the parameters for the service, at least the ListName and perhaps the number of items you want to display.
- On the Login tab, provide an account to login when nescessary. Only providing a textbased account seems to work here and I found that it’s quite difficult to authenticate against claims based sites, so I use a Windows based extended site instead.
- Open up the page on which you want to add the blog messages. Via Insert -> DataView, insert your blog datasource. This step is only necessary to copy the datasource XML.
- Now paste in the following webpart code:
<xsl:template match=”/” xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:ddw1=”http://schemas.microsoft.com/sharepoint/soap/” xmlns:rs=”urn:schemas-microsoft-com:rowset” xmlns:z=”#RowsetSchema” xmlns:asp=”http://schemas.microsoft.com/ASPNET/20″ xmlns:__designer=”http://schemas.microsoft.com/WebParts/v2/DataView/designer” xmlns:SharePoint=”Microsoft.SharePoint.WebControls”><?xml version="1.0" encoding="utf-8"?>
<WebPartPages:DataFormWebPart runat="server" Description="" ImportErrorMessage="Kan dit webonderdeel niet importeren." PartOrder="4" HelpLink="" AllowRemove="True" IsVisible="True" AllowHide="True" UseSQLDataSourcePaging="True" ExportControlledProperties="True" DataSourceID="" Title="Software blog berichten" ViewFlag="8" NoDefaultStyle="TRUE" AllowConnect="True" FrameState="Normal" PageSize="10" PartImageLarge="" AsyncRefresh="True" ExportMode="All" Dir="Default" DetailLink="/blog" ShowWithSampleData="False" ListId="00000000-0000-0000-0000-000000000000" ListName="" FrameType="Default" PartImageSmall="" IsIncluded="True" SuppressWebPartChrome="False" AllowEdit="True" ManualRefresh="False" AutoRefresh="False" AutoRefreshInterval="60" AllowMinimize="True" ViewContentTypeId="" InitialAsyncDataFetch="False" MissingAssembly="Kan dit webonderdeel niet importeren." HelpMode="Modeless" ID="g_7df1d3ab_255e_4941_9d0e_c5a4bc0eb913" ConnectionID="00000000-0000-0000-0000-000000000000" AllowZoneChange="True" TitleUrl="/blog" IsIncludedFilter="" __MarkupType="vsattributemarkup" __WebPartId="{8C6B1959-47C0-4AB0-A023-FDB4D9144284}" __AllowXSLTEditing="true" WebPart="true" Height="" Width="">
<ParameterBindings>
<ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
<ParameterBinding Name="ManualRefresh" Location="WPProperty[ManualRefresh]"/>
<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
<ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
</ParameterBindings>
<DataFields>@ows_LinkTitle,ows_LinkTitle;@ows_PostCategory,ows_PostCategory;@ows_Body,ows_Body;@ows_PostedByWithDate,ows_PostedByWithDate;@ows__ModerationStatus,ows__ModerationStatus;@ows__Level,ows__Level;@ows_Title,ows_Title;@ows_PublishedDate,ows_PublishedDate;@ows_ID,ows_ID;@ows_UniqueId,ows_UniqueId;@ows_owshiddenversion,ows_owshiddenversion;@ows_FSObjType,ows_FSObjType;@ows_Created_x0020_Date,ows_Created_x0020_Date;@ows_Created,ows_Created;@ows_FileLeafRef,ows_FileLeafRef;@ows_PermMask,ows_PermMask;@ows_Modified,ows_Modified;@ows_FileRef,ows_FileRef;</DataFields>
<Xsl>
<xsl:stylesheet xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ddw1="http://schemas.microsoft.com/sharepoint/soap/" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:output method="html" indent="no"/>
<xsl:decimal-format NaN=""/>
<xsl:param name="dvt_apos">'</xsl:param>
<xsl:param name="ManualRefresh"></xsl:param>
<xsl:variable name="dvt_1_automode">0</xsl:variable>
<xsl:choose>
<xsl:when test=”($ManualRefresh = ‘True’)”>
<table width=”100%” border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td valign=”top”>
<xsl:call-template name=”dvt_1″/>
</td>
<td width=”1%” class=”ms-vb” valign=”top”>
<img src=”/_layouts/images/staticrefresh.gif” id=”ManualRefresh” border=”0″ onclick=”javascript: {ddwrt:GenFireServerEvent(‘__cancel’)}” alt=”Click here to refresh the dataview.”/>
</td>
</tr>
</table>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name=”dvt_1″/>
</xsl:otherwise>
</xsl:choose>
</xsl:template><xsl:template name=”dvt_1.empty”>
<xsl:variable name=”dvt_ViewEmptyText”>There are no items to show in this view.</xsl:variable>
<table border=”0″ width=”100%”>
<tr>
<td class=”ms-vb”>
<xsl:value-of select=”$dvt_ViewEmptyText”/>
</td>
</tr>
</table>
</xsl:template>
<xsl:template name=”dvt_1″>
<xsl:variable name=”dvt_StyleName”>RepForm1</xsl:variable>
<xsl:variable name=”Rows” select=”/soap:Envelope/soap:Body/ddw1:GetListItemsResponse/ddw1:GetListItemsResult/ddw1:listitems/rs:data/z:row” />
<xsl:variable name=”dvt_RowCount” select=”count($Rows)” />
<xsl:variable name=”dvt_IsEmpty” select=”$dvt_RowCount = 0″ />
<xsl:choose>
<xsl:when test=”$dvt_IsEmpty”>
<xsl:call-template name=”dvt_1.empty” />
</xsl:when>
<xsl:otherwise>
<table border=”0″ width=”100%”>
<xsl:call-template name=”dvt_1.body”>
<xsl:with-param name=”Rows” select=”$Rows” />
</xsl:call-template>
</table>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name=”dvt_1.body”>
<xsl:param name=”Rows” />
<xsl:for-each select=”$Rows”>
<xsl:call-template name=”dvt_1.rowview” />
</xsl:for-each>
</xsl:template>
<xsl:template name=”dvt_1.rowview”>
<tr>
<td class=”ms-leftblogdate” style=”vertical-align: top;”>
<div class=”ms-postcalendardateboxtop” id=”PostDateTopBox{generate-id()}”/>
<div class=”ms-postcalendardateboxbottom” id=”PostDateBottomBox{generate-id()}” style=”overflow-x: hidden;”>
<div>
<xsl:value-of select=”ddwrt:FormatDate(@ows_PublishedDate, 2057, 3)”/>
</div>
</div>
</td>
<td width=”100%” colspan=”2″ class=”ms-vb”>
<div class=”ms-PostTitle”>
<a href=”/site/blog/Lists/Berichten/Post.aspx?ID={@ows_ID}”>
<xsl:value-of select=”@ows_LinkTitle” />
</a>
</div>
<div class=”ms-PostFooter”>
Door: <xsl:value-of select=”@ows_PostedByWithDate” />
</div>
<div class=”ms-PostBody”>
<xsl:value-of select=”@ows_Body” disable-output-escaping=”yes” />
</div>
<div class=”ms-PostFooter”>
<span style=”vertical-align: middle”>
<span style=”position: relative; width: 16px; display: inline-block; height: 16px; overflow: hidden” class=”s4-clust”>
<a style=”width: 16px; display: inline-block; height: 16px” href=”//blog/Lists/Berichten/Post.aspx?ID={@ows_ID}”>
<img style=”position: absolute; top: -412px !important; left: 0px !important” class=”imglink” title=”Vaste koppeling naar bericht” alt=”Vaste koppeling naar bericht” src=”/_layouts/images/fgimg.png” longDesc=”Vaste koppeling naar bericht”/>
</a>
</span>
</span>
 | 
<span style=”vertical-align: middle”>
<span style=”position: relative; width: 16px; display: inline-block; height: 16px; overflow: hidden” class=”s4-clust”>
<a style=”width: 16px; display: inline-block; height: 16px” href=”javascript:navigateMailToLink(‘/site/blog%2FLists%2FBerichten%2FPost.aspx?ID%3D{@ows_ID}’)”>
<IMG style=”position: absolute; TOP: -267px !important; left: 0px !important” class=”imglink” title=”Koppeling naar E-mail verzenden” alt=”Koppeling naar E-mail verzenden” src=”/_layouts/images/fgimg.png” longDesc=”Koppeling naar E-mail verzenden”/>
</a>
</span>
</span>
 | 
<span style=”vertical-align: middle”>
<span style=”position: relative; width: 16px; display: inline-block; height: 16px; overflow: hidden” class=”s4-clust”>
<a style=”width: 16px; display: inline-block; height: 16px” href=”/site/blog/Lists/Berichten/Post.aspx?ID={@ows_ID}”>
<img style=”position: absolute; top: -396px !important; left: 0px !important” class=”imglink” title=”Aantal opmerkingen” alt=”Aantal opmerkingen” src=”/_layouts/images/fgimg.png” longDesc=”Aantal opmerkingen”/>
</a>
</span>
</span>
<span>
<a href=”/site/blog/Lists/Berichten/Post.aspx?ID={@ows_ID}”>
 <xsl:value-of select=”@ows_NumComments”/> Opmerking(en)
</a>
</span>
</div>
<br/>
<br/>
</td>
</tr>
<xsl:if test=”$dvt_1_automode = ‘1’” ddwrt:cf_ignore=”1″>
<tr>
<td width=”100%” colspan=”2″ class=”ms-vb”>
<span ddwrt:amkeyfield=”” ddwrt:amkeyvalue=”string($XPath)” ddwrt:ammode=”view” />
</td>
</tr>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
</Xsl>
<DataSources>
<SharePoint:SoapDataSource runat=”server” SelectUrl=”http://sharepoint/site/blog/_vti_bin/lists.asmx” InsertUrl=”” UpdateUrl=”” DeleteUrl=”” SelectAction=”http://schemas.microsoft.com/sharepoint/soap/GetListItems” InsertAction=”” UpdateAction=”” DeleteAction=”” SelectPort=”ListsSoap” InsertPort=”” UpdatePort=”” DeletePort=”” SelectServiceName=”Lists” InsertServiceName=”” UpdateServiceName=”” DeleteServiceName=”” AuthType=”Basic” AuthUserName=”DOMAIN\account” AuthPassword=”password” WsdlPath=”http://sharepoint/site/blog/_vti_bin/lists.asmx?WSDL” XPath=”” ID=”BlogBerichten4″>
<SelectCommand>
<soap:Envelope xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”>
<soap:Body>
<GetListItems xmlns=”http://schemas.microsoft.com/sharepoint/soap/”>
<listName>Messages</listName>
<rowLimit>2</rowLimit>
</GetListItems>
</soap:Body>
</soap:Envelope>
</SelectCommand>
<InsertCommand></InsertCommand>
<UpdateCommand></UpdateCommand>
<DeleteCommand></DeleteCommand>
</SharePoint:SoapDataSource>
</DataSources>
</WebPartPages:DataFormWebPart> - Click on “Advanced Edit” in the ribbon and add this code to the AdditionalPageHead content placeholder:
<SharePoint:CssRegistration runat="server" name="Themable/blog.css">
</SharePoint:CssRegistration>
This will add the nescessary CSS styles the blog template uses. - Now copy/paste the <datasources> nodes from your previously added webpart and overwrite this section in the above code. This links your dataformwebpart to the correct webservice.
- A couple of things to note: the URLs in this code are relative to the server URL, so if your blog lives on a different path (which it probably does), you need to check the URLs and correct them. Also, the above snippet is in Dutch, so for English you need to make some little changes too.
- When you now save and view the page, you’ll notice that there’s no author name supplied. That’s beacuse the webservice isn’t returning this data. Why? Because the default view of the Messages list in your blog doesn’t include this field (author and date published). You can fix this in two ways: either create a new view with all the nessecary fields and set the view ID in the webservice parameters, or just include the field in the default view (my preference).
- Ok, all set now. Refresh your page and it should properly display your blog posts like the way the are on the blog site itself! Offcourse you can adapt and play with the XSL code in the webpart to adjust this to your needs. If you want to add more fields, just remember to include them in the default view or your custom view on the Messages list of your blog.
Leave a Comment