News feed

Topics: Standard packages, XSLT
Sep 15, 2011 at 10:30 AM

Hi,

I have the Blog package installed.

I would like to display a feed on the home page, showing links to the 5 most recent posts tagged with "News".

What's the best way to implement this?

I tried adding the Blog Archive function to the home page, but it doesn't render.

I thought about feeding off the RSS feed, but I can't filter it by tag (I don't think).

Any ideas / suggestions much appreciated.

Thanks,

Rob

Coordinator
Sep 15, 2011 at 1:23 PM
robertmorgan wrote:

Hi,

I have the Blog package installed.

I would like to display a feed on the home page, showing links to the 5 most recent posts tagged with "News".

What's the best way to implement this?


Hello,

I suggest to create XSTL function, f.e named Composite.Community.Blog.GetLatestByTag:

1) Input parameters: add two input parameters: Tag (string) and Count (int, default is 5)

2) Function calls (source view):

<f:functions xmlns:f="http://www.composite.net/ns/function/1.0">
	<f:function name="Composite.Community.Blog.Entries.GetEntriesXml" localname="GetEntriesXml">
		<f:param name="PropertyNames">
			<f:paramelement value="PageId" />
			<f:paramelement value="Date" />
			<f:paramelement value="Tags" />
			<f:paramelement value="Id" />
			<f:paramelement value="Title" />
		</f:param>
		<f:param name="Filter">
			<f:function name="Composite.Community.Blog.Entries.FieldPredicatesFilter">
				<f:param name="Tags">
					<f:function name="Composite.Utils.Predicates.StringContains">
						<f:param name="Value">
							<f:function name="Composite.Utils.GetInputParameter">
								<f:param name="InputParameterName" value="Tag" />
							</f:function>
						</f:param>
					</f:function>
				</f:param>
			</f:function>
		</f:param>
		<f:param name="OrderByField" value="Date" />
		<f:param name="OrderAscending" value="False" />
		<f:param name="PageSize">
			<f:function name="Composite.Utils.GetInputParameter">
				<f:param name="InputParameterName" value="Count" />
			</f:function>
		</f:param>
	</f:function>
	<f:function name="Composite.Community.Blog.XsltExtensions" localname="XsltExtensions" />
</f:functions>

3) Template tab:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:in="http://www.composite.net/ns/transformation/input/1.0" 
xmlns:lang="http://www.composite.net/ns/localization/1.0" 
xmlns:f="http://www.composite.net/ns/function/1.0" 
xmlns="http://www.w3.org/1999/xhtml" 
xmlns:be="#BlogXsltExtensionsFunction" 
exclude-result-prefixes="xsl in lang f be">
  <xsl:variable name="entries" select="/in:inputs/in:result[@name='GetEntriesXml']/Entries" />
  <xsl:template match="/">
    <html>
      <head></head>
      <body>
        <ul>
          <xsl:apply-templates mode="LatestList" select="$entries" />
        </ul>
      </body>
    </html>
  </xsl:template>
  <xsl:template mode="LatestList" match="*">
    <li>
      <a href="~/Renderers/Page.aspx{be:GetBlogUrl(@Date, @Title)}?pageId={@PageId}" title="{@Title}">
        <xsl:value-of select="@Title" />
      </a>
    </li>
  </xsl:template>
</xsl:stylesheet>

 

Sep 20, 2011 at 10:23 AM

Thanks Inna - works perfectly.

Couple of extra things I need:

1. Date formatted as follows:

20 Sep 2011

2. Snippet of blog post content (max 70 chars).

Would really appreciate it if you would point me in the right direction.

Thanks again,

Rob

Coordinator
Sep 20, 2011 at 11:01 AM

Hi,

1. If you Preview your XSLT (just make sure that input parameters have test or default values), you will see what functions #BlogXsltExtensions have, for example   <!-- String ns:CustomDateFormat(DateTime date, String dateFormat) --> , so you can use this extension to show date, like this:

 <xsl:value-of select="be:CustomDateFormat(@Date,'dd MMM yyyy')" />

2. Use Teaser field and xslt substring function:

 <xsl:value-of select="substring(@Teaser,0,70)" />

Sep 20, 2011 at 11:34 AM

Awesome - thanks.

Sep 20, 2011 at 10:41 PM

One thing to keep in mind. If you have more than one blog, this will pull from BOTH. IF you want to specify which blog, you'll also need a Filter on the PageId in the FieldPredicatesFilter

May 2, 2013 at 12:44 AM
I'm getting this error:

Error: Extension object '#BlogXsltExtensionsFunction' does not contain a matching 'GetBlogUrl' method that has 2 parameter(s).

What could be causing this?