6

We have a SharePoint blog site, with the default Posts view on the home page. Some of the posts are quite long, and take up all of the page, removing any value in having a list of posts on the homepage.

We'd like to use the homepage as a post preview page and as such want to restrict each entry to only show a preview of each post, such as with the Read More link you can add in a WordPress blog.

We'd ideally like to not have to embed code in each post, but I have not been able to find an OOB solution either via my own experimenting or online.

SP 2010 Enterprise

1

You can use search based solution like in this post Creating a latest blog posts web part

The steps to do this are:

  • Perform a full crawl of a content source which has at least one blog post and a comment
  • Add a Managed Property for the number of comments and name it something appropriate, e.g. NumComments
  • Add a Search Core Results web part to the page you wish to display the latest blog posts web part on:
    • I’ve chosen the My Newsfeed page so that it can display alongside the Activity Feed
    • It may be necessary to activate the Search Server Web Parts site collection feature if the web parts are not immediately available
  • Configure the Search Core Results web part:
    • Add a column mapping for the new managed property NumComments
    • Add in customised XSL to display the results
    • Provide a Fixed Keyword Query of “contenttype:post”
    • Limit the amount of items returned (I’ve gone for 5 in this example)
    • Modify to sort the results by modified date

The XSL I’ve used for the web part:

<xsl:stylesheet xmlns:x= "http://www.w3.org/2001/XMLSchema"
    xmlns:d= "http://schemas.microsoft.com/sharepoint/dsp"
    version= "1.0"
    exclude-result-prefixes= "d xsl msxsl ddwrt xmlns x __designer WebControls asp ddwrt2"
    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:WebControls= "Microsoft.Sharepoint.WebControls"
    xmlns:ddwrt2= "urn:frontpage:internal">
  <xsl:output method="html" indent="no"/>

  <xsl:template match="Result">
    <xsl:variable name="blogPath">
      <xsl:call-template name="getblogpath">
        <xsl:with-param name="encodedPath" select="url" />
      </xsl:call-template>
    </xsl:variable>

    <li class="blogListPost">
      <!-- date box -->
      <div class="blogListPostDate">
        <div class="ms-postcalendardateboxtop" id="PostDateTopBox"/>
        <div class="ms-postcalendardateboxbottom" id="PostDateBottomBox">
          <div>
            <xsl:value-of select="ddwrt:FormatDateTime(string(write),1033, 'MMMM dd')" />
          </div>
        </div>
      </div>
      <div class="blogListPostBlock">
        <!-- Title -->
        <h4>
          <a style="color: #295AC6;">
            <xsl:attribute name="href">
              <xsl:value-of select="url"/>
            </xsl:attribute>
            <xsl:value-of select="title" />
          </a>
        </h4>
        <!-- Date and Summary -->
        <div class="blogListPostPostedDateAndSummary">
          <span class="ms-PostFooter blogListPostPostedBy">
            Posted by
            <xsl:value-of select="author" disable-output-escaping="yes" />
            on
            <xsl:value-of select="ddwrt:FormatDate(string(write),1027, 1)" />
          </span>
          <p class="ms-PostBody blogListPostBody">
            <xsl:value-of select="hithighlightedsummary" disable-output-escaping="yes" />...
          </p>
        </div>
        <!-- Blog links -->
        <ol class="blogListPostLinks">
          <!-- Permalink -->
          <li class="blogListPostLinksItem">
            <span style="vertical-align:middle;">
              <span style="position: relative; width: 16px; display: inline-block; height: 16px; overflow: hidden;">
                <a style="width: 16px; display: inline-block; height: 16px;">
                  <xsl:attribute name="href">
                    <xsl:value-of select="url"/>
                  </xsl:attribute>
                    <img longdesc="Permanent Link to Post" class="imglink" title="Permanent Link to Post" style="left: 0px ! important; top: -412px ! important; position: absolute;" alt="Permanent Link to Post" src="/_layouts/images/fgimg.png" />
                </a>
              </span>
            </span>
          </li>
          <!-- Email link -->
          <li class="blogListPostLinksItem">
            <span style="vertical-align: middle;">
              <span style="position: relative; width: 16px; display: inline-block; height: 16px; overflow: hidden;">
                <a style="width: 16px; display: inline-block; height: 16px;">
                  <xsl:attribute name="href">
                    javascript:navigateMailToLink('
                    <xsl:value-of select="url"/>
                    ')
                  </xsl:attribute>
                  <img longdesc="Email Post Link" class="imglink" title="Email Post Link" style="left: 0px ! important; top: -267px ! important; position: absolute;" alt="Email Post Link" src="/_layouts/images/fgimg.png" />
                </a>
              </span>
            </span>
          </li>
          <!-- Comments -->
          <li class="blogListPostLinksItem last">
            <span style="vertical-align: middle;">
              <span style="position: relative; width: 16px; display: inline-block; height: 16px; overflow: hidden;">
                <a style="width: 16px; display: inline-block; height: 16px;">
                  <xsl:attribute name="href">
                    <xsl:value-of select="url"/>
                  </xsl:attribute>
                  <img longdesc="Number of Comments" class="imglink" title="Number of Comments" style="left: 0px ! important; top: -396px ! important; position: absolute;" alt="Number of Comments" src="/_layouts/images/fgimg.png" />
                </a>
              </span>
              <span>
                <a>
                  <xsl:attribute name="href">
                    <xsl:value-of select="url"/>
                  </xsl:attribute>
                  <xsl:text>
                                </xsl:text>
                  <xsl:value-of select="numcomments"/>
                  Comment(s)
                </a>
              </span>
            </span>
          </li>
        </ol>
      </div>
    </li>
  </xsl:template>

  <xsl:template match="TotalResults">
  </xsl:template>
  <xsl:template match="NumberOfResults">
  </xsl:template>

  <xsl:template name="getblogpath">
    <xsl:param name="encodedPath"/>
    <xsl:choose>
      <xsl:when test="contains($encodedPath, '/')">
        <xsl:value-of select="substring-before($encodedPath, '/')"/>/<xsl:call-template name="getblogpath">
          <xsl:with-param name="encodedPath" select="substring-after($encodedPath, '/')" />
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="/">
    <link rel="stylesheet" type="text/css">
      <xsl:attribute name="href">
        /_layouts/1033/styles/Themable/blog.css
      </xsl:attribute>
    </link>
    <style type="text/css">
      .s4-ca {width:100%;}
      .blogList {list-style-type: none; padding:0;margin:0;}
      .blogListPost {border-bottom:1px dashed #CCCCCC;padding:10px 0;margin:0;}
      .blogListPost:hover {background-color:#F5F5F5;}
      .blogListPostDate {float:left;width:90px;padding-left:20px;}
      .blogListPostBlock {margin-left:110px;}
      .blogListPostBlock h4 {padding:0;margin:0;}
      .blogListPostPostedDateAndSummary {display:block;}
      .blogListPostPostedBy { }
      .blogListPostBody {padding-top:0px;padding-bottom:0;}
      .blogListPostLinks {list-style-type:none;padding:0;}
      .blogListPostLinksItem {display:inline;padding:0 10px 0 10px;border-right:Solid 1px #999999;}
      .blogListPostLinksItem.last {border:none;}
    </style>
    <ol class="blogList">
      <xsl:apply-templates/>
    </ol>
  </xsl:template>

  <!-- End of Stylesheet -->
</xsl:stylesheet>
  • 1
    Please add details from the link to your answer. If the link breaks, your answer will be of little to no help at all as it stands now :) – Robert Lindgren Nov 25 '13 at 18:10
  • Thanks Andrew, but I'm having some difficulty picking out the relevent parts from this: this post is on pulling together posts from various locations. Can you confirm which part of this provides the solution to my question? – CLockeWork Nov 26 '13 at 13:15
  • XSL style sheet in example illustrated how you can change the view of blog post items. Using that you can add link for "Read more" and other functionality that you need. – Andrey Ungur Nov 26 '13 at 13:40
  • I could indeed, if I knew anything about XSL :( Sadly I wouldn't know where to begin pulling out the bits that aren't relevent and adding bits that are. Thanks anyway Andrew. – CLockeWork Nov 26 '13 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.