Copied to clipboard

Flag this post as spam?

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


  • Greyhound 102 posts 124 karma points
    Aug 03, 2010 @ 16:24
    Greyhound
    0

    NodeFactory

    Hi,

    Not sure whether I'm going about this is the right way or not:

    Scenario:
    1. Need to get the latest Blog4Umbraco posts using C# in a user control

    So far I can get a list of the children nodes but only one step down, for example, I have the following:

    Blog
    >2010
    >About
    >Tag Cloud
    >Archive

    It will return me types of Date Folder, BlogTextPage.

    What I would like to do is get all blog posts (excluding comments) in one go then arrange them by date.

    Does any one know of the c# syntax to enable me to get straight at the blog posts using the main Blog node ID?

    Ps. I am doing this in a user control as I have a telerik rotator control that I wish to show them in.

    Thanks in advance.

  • Sascha Wolter 615 posts 1101 karma points
    Aug 03, 2010 @ 16:55
    Sascha Wolter
    0

    Hi Greyhound,

    if you are using 4.5 the best way to do this would be LINQ to Umbraco I guess (haven't used it myself though, so can't help you there I'm afraid).

    Otherwise you can manually traverse the nodes, e.g.

    Node blog = new Node(your-blog-root-id);
    foreach (Node year in blog.Children){
      if (year.NodeTypeAlia=="year-node-type-alias"){
        foreach (Node month in year.Children){
          //etc until you reach the blog posts, then put them in a custom List<MyBlogStructure>
        }
      }
    }

    Or traverse the nodes in the backend via a XPathNavigator object and an XPath expression

    XPathNavigator xpn = umbraco.content.Instance.XmlContent.CreateNavigator();
    XPathNodeIterator xpni = xpn.Select("xpath expression to get all blog posts");
    xpni.MoveNext();
    //Then loop through the XPathNodeIterator

    Hope that was what you were looking for,

    Sascha

  • Greyhound 102 posts 124 karma points
    Aug 03, 2010 @ 17:29
    Greyhound
    1

    Thanks for the info.

    I've had a play and have come up with the following:

    XPathNavigator xpn = umbraco.content.Instance.XmlContent.CreateNavigator();
    XPathNodeIterator xpni = xpn.Select("//node [@nodeTypeAlias = 'BlogPost']");
    while (xpni.MoveNext())
    {
    XPathNavigator node = xpni.Current;
    string BlogTitleAttribute = node.GetAttribute("nodeName", "");
    Response.Write(BlogTitleAttribute);
    }

     

    This returns the attribute nodeName from the XML output of the Blog post item.

    Thank you very much for pointing me in the right direction.

  • Sascha Wolter 615 posts 1101 karma points
    Aug 04, 2010 @ 11:56
    Sascha Wolter
    0

    Fantastic! :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies