Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • FarmFreshCode 225 posts 422 karma points
    Apr 19, 2011 @ 19:24
    FarmFreshCode
    0

    blog4umbraco - Dynamic Archives

    Hello everyone. I am looking to create a dynamic archiving list for my blog4umbraco installation.I am using umbraco v4.7.

    I would like to continue to show the months within the current calendar year, but compress all years older. This would help keep my archive under reasonable control. By automatically compressing all 2009 articles into a single list item I can remove all of the individual months for that year and shorten the space required to show archives.

    Would anyone know how to make this happen?

    Thank you in advance.

  • webangelo 107 posts 190 karma points
    Apr 19, 2011 @ 19:41
    webangelo
    0

    Does it matter to you whether it happens in a single pass vs. a double pass (i.e. one pass for the current year and one for the previous years)? 

    Also are you looking for xslt, razor or DotNET (or does it matter to you)?

  • FarmFreshCode 225 posts 422 karma points
    Apr 19, 2011 @ 22:05
    FarmFreshCode
    0

    I would think a single pass would be the best, and XSLT was my thought only be cause that's all I've used so far. I am pretty new to Umbraco and .NET so any solution that created the end result would be excellent. I just would like it to work within the blog4umbraco structure so I can still continue to use that configuration.

  • FarmFreshCode 225 posts 422 karma points
    Apr 20, 2011 @ 16:04
    FarmFreshCode
    0

    What would you suggest as the best solution?

  • webangelo 107 posts 190 karma points
    Apr 20, 2011 @ 19:37
    webangelo
    0

    Hmm,  it appears my reply didn't get posted.  Lets try again.

    The blog4umbraco archive list code by default uses a double for-each, one to select each year folder and a nested one to select the month folders with in a year.  To do what you want you will have to add an xsl:choose around the inner for-each to only do that if you are in the current year.  (I'm doing this with out somewhere to test, so it may need to be tweaked).

    <xsl:for-each select="$currentPage/ancestor-or-self::Blog/DateFolder">
    <xsl:sort select="@nodeName" data-type="number" order="descending" />
    <xsl:choose>
    <xsl:when test="@nodeName = Exslt.ExsltDatesAndTimes:year()">
    <xsl:for-each select="./DateFolder">
    <xsl:sort select="@nodeName" data-type="number" order="descending" />
    <li class="month">
    <xsl:variable name="monthname" select="umbraco.library:FormatDateTime(concat(./../@nodeName,'-',@nodeName,'-11T10:24:46'),'MMMM yyyy')" />
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="$monthname"/>
    </a>&nbsp;<span>
    (<xsl:value-of select="count(.//BlogPost)"/>)
    </span>
    </li>
    </xsl:for-each>
    </xsl:when>
    <xsl:otherwise>
    <li class="month">
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>&nbsp;<span>
    (<xsl:value-of select="count(.//BlogPost)"/>)
    </span>
    </li>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:for-each>

    Give this a try keeping in mind you may have to add the Exslt.ExsltDatesAndTimes declaration to the xsl:stylesheet area of your xslt file so you can call the year() function as I believe blog4umbraco only includes the declarations necessary for the specific functionality it uses.

    Let me know if this works for you or if you have any questions.

  • FarmFreshCode 225 posts 422 karma points
    Apr 20, 2011 @ 19:50
    FarmFreshCode
    0

    @webangelo - Thanks for getting back to me, I dropped in the code you provided and got an error.

    This is probably exactly what you were talking about with the "Exslt.ExsltDatesAndTimes declaration" but I am affraid I'm not sure how I should add that.

    My current stylesheet looks like this:

    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library"
      exclude-result-prefixes="msxml umbraco.library">

     

  • webangelo 107 posts 190 karma points
    Apr 20, 2011 @ 20:28
    webangelo
    0

    It should at least look like the following:

    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltDatesAndTimes">
  • FarmFreshCode 225 posts 422 karma points
    Apr 20, 2011 @ 20:42
    FarmFreshCode
    0

    @webangelo - Ah.. got it! I have a very limited number of posts in my blog at the moment, but for the sample ones that I have put in, it worked immediately!
    THANK YOU! - I'll be sure to give you credit on my blog post about this item! I've also added you to my Umbraco List of helpers on twitter!

  • FarmFreshCode 225 posts 422 karma points
    Apr 20, 2011 @ 21:37
    FarmFreshCode
    0

    @webangelo - well... actually I came into a problem.. but it has nothing to do with your solution.. when I click on a link for an archived year I am sent to:
    http://localhost/2010.aspx
    and these pages are not found?

    "Page not found
    No umbraco document matches the url 'http://localhost/2003.aspx'
    umbraco tried this to match it using this xpath query'2003')"

    Also, when I click "April 2011 -> http://localhost/2011/4.aspx", or ""March 2011 -> http://localhost/2011/3.aspx"..ect.  my archive page is showing all of the posts within the blog.. not just those restricted to that month or even that year..

    I have reinstalled the blog to start over with a fresh install and I am still seeing this problem...even without including your code. Any idea on the problem?

  • FarmFreshCode 225 posts 422 karma points
    Apr 20, 2011 @ 21:52
    FarmFreshCode
    0

    Ok, I found the solution for the bad archive links here:
    http://our.umbraco.org/projects/collaboration/blog-4-umbraco/using-blog-4-umbraco/16031-Blog-Archive-Problem

    Thanks again for your help!

  • FarmFreshCode 225 posts 422 karma points
    Apr 20, 2011 @ 23:24
    FarmFreshCode
    0

    Grr FAIL, not sure what happened but the yearly archive pages ( /2010.aspx ) just throw up 404 errors again.. no idea why.. :-(

  • webangelo 107 posts 190 karma points
    Apr 21, 2011 @ 05:09
    webangelo
    1

    This seems to be related to codeplex issue 25741 in which a numeric root node using a .aspx extension gets a 404.  A work around is to set the umbracoUseDirectoryUrls value in your web.config to true, which should give you urls like http://localhost/2010/ instead.  Alternatively, you can move the numeric folders off the root by setting umbracoHideTopLevelNodeFromPath in your web.config to false.

  • FarmFreshCode 225 posts 422 karma points
    Apr 21, 2011 @ 14:03
    FarmFreshCode
    0

    @webangelo - thank you! First I tried the "umbracoUseDirectoryURLs" but then that broke my tag links. :-(  So then I tried the umbracoHideTopLevelNodeFromPath setting to false. This option worked and helped me to finally get all of these links working correctly. But I really wanted the clean directory links so, then I tried both the changes you mentioned together and I think I finally have it... wooooooooooo

    Thanks so much for sticking it out with me, I really appreciate it. On the plus side, I have uninstalled, reinstalled, and made the fixes to this blog so many times now I think I could do it blindfolded. We'll call the last 24 hours a lesson in tough love.

Please Sign in or register to post replies

Write your reply to:

Draft