Copied to clipboard

Flag this post as spam?

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


  • Chad 65 posts 129 karma points c-trib
    Jan 31, 2010 @ 05:06
    Chad
    0

    Automatically changing URL Redirect based on child nodes

    Absolutely crappy thread post. I apologise for that, let me explain. My nodes look like so:

     

    Publications
      - 2010
        -- January
        -- February
      - 2009
        -- January
        -- February
        -- March
        -- And so on...

    What I'd like is when someone browses to Publications, it will redirect them to the LAST child node of the FIRST child node of publications. In this case, 2010/February. When March is added, it will then go to March. When 2011/January is added, it will then be selected.

    Basically I just want them to be redirected to the latest publications.

    I've now idea on how to accomplish this in umbraco.

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Jan 31, 2010 @ 09:59
    Morten Bock
    0

    You could put a usercontrol on your Publications templates, that has the logic for getting the correct month, and does the redirect.

    To find the nodes use umbraco.presentation.nodeFactory.Node.GetCurrent().Children which will get you a collection of nodes. In this case they would be 2010/2009 and so on.

  • Rich Green 2246 posts 4008 karma points
    Jan 31, 2010 @ 11:19
    Rich Green
    0

    Morten's solution will certainly work, however If you feel more comfortable using XSLT i'm pretty sure this could be done by putting a macro in your 'publications' template, then in your XSLT you would need to grab the 'First' year node, and the 'last' Month node, using XSLT Position().

  • Rich Green 2246 posts 4008 karma points
    Jan 31, 2010 @ 11:21
    Rich Green
    0

    The XSLT solution above would rely on your user putting the years / dates in correct order.

    Though thinking about it I'm sure you could do some fancy date algorithm to grab the actual latest year and latest month regardless of node position. 

  • Rich Green 2246 posts 4008 karma points
    Jan 31, 2010 @ 11:27
    Rich Green
    0

    (Where's the darn edit feature!)

    With both of the XSLT solutions you would redirect to the correct node in the XSLT.

    Here's an old post which does it using javascript thought you can do a server redirect in XSLT too.

  • Chad 65 posts 129 karma points c-trib
    Jan 31, 2010 @ 23:54
    Chad
    0

    "thought you can do a server redirect in XSLT too."

    How? I'm looking through the umbraco.library xslt extensions and can't see any redirect methods?

    I find working in XSLT to be much less friction then working with user controls (as alien as XSLT and XPATH is to me).

  • Chad 65 posts 129 karma points c-trib
    Feb 01, 2010 @ 01:05
    Chad
    0

    Gave up with XSLT, just ended up doing this:

     

    Nodes nodes = umbraco.presentation.nodeFactory.Node.GetCurrent().Children[0].Children;
    Response.Redirect(umbraco.library.NiceUrl(nodes[nodes.Count -1].Id));
Please Sign in or register to post replies

Write your reply to:

Draft