Est. Reading Time: 7 minutes
One of our recent enhancements to the Beacon website included integrating components of our blog into the content of the site. This is visible on the homepage under the “Blog” tab and shows the three most recent postings on our WordPress blog. Additionally, we decided to include links to recent blog links by categories or topic on the page. For example, the SEO Management page would produce blog links that fell in the SEO category. This is applied throughout the site on interior pages, which is effective for SEO as each page will be updated with every blog posting we create (given the post falls in the category of the page displayed).
The blog feed on the homepage was much easier in comparison worked like this:
XSLT Format used in Cascade:
This is a simple ASP literal that will be the populated by the blog feed.
<xsl:comment>#START-CODE<asp:Literal id=”litFeedReaderBlog” runat=”server”/>#END-CODE</xsl:comment>
VB for CodeBehind File:
VB CodeBehind File (.pdf)
This small set of code basically links to page with RSS feed, in this case, the general RSS feed for entire blog. The part shown in red needs to match the URL of the RSS feed to your particular WordPress site. The part shown in green is a relative path to the XSL file you will use to format the output. Lastly, the part in blue needs to match the ID of your ASP literal so the codebehind knows where to place the output.
Most WordPress sites use the following schema to the feed: http://sitename.com/rss
The above linked RSS page acts as the data source for the VB CodeBehind file and uses an XSL file (shown below) to format the output to the page. Because this RSS page is updated and managed by WordPress, the output is always up to date with the blog.
XSLT used by CodeBehind File for Output:
XSLT File (.pdf)
So, if you followed all that and put it into practice, you get something like this (after styling):
The code and logic above was primarily followed for the related links, but had to be modified to fit the following specs:
At first, the solution Justin and I had come up with, was to make the VB smart enough to recognize when less than 3 posts were output and go out and grab the remaining from the parent category. The issue with this was that the parent category of any category might list already output postings by the sub-category (since they are listed in order of most recent). Therefore, we had to heavily modify the codebehind file in a way that it would ALSO recognize not to output duplicate posts from the parent category.
XSLT Format and Template Changes in Cascade:
Every page needs to get the codebehind file. In Cascade, this is accomplished by adding the following to the template:
<!–#START-ROOT-CODE<%@ Page Language=”VB” aspcompat=”true” AutoEventWireup=”false” CodeFile=”/rightColumnBlogFeed.aspx.vb” Inherits=”_Default” %>#END-ROOT-CODE–>
We saw that http://www.beacontechnologies.com/blog/feed shows a listing from all categories (10 of the most recent being shown). We can change the URL to include one of our categories, say… Web Marketing — just by changing the URL to http://www.beacontechnologies.com/blog/category/web-marketing/feed. Notice the RSS feed is then modified to fit the category and still listed (as defaulted in WordPress) by most recent posts. The XSLT file below was used to select either the post category or section for outputting the text attribute of the ASP literal.
Modified XSLT File (.pdf)
Changes in VB Codebehind & CodeBehind’s XSLT
While I’d prefer not to share our exact source code, here are the modification necessary to the templated file above to prevent duplicate stories from being output.