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
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.
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
Thanks for the info.
I've had a play and have come up with the following:
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.
Fantastic! :)
is working on a reply...