I have the following code which is working great apart from it's returning nodes that aren't published. Where would I need to tweak it ? I presume I need a .Where("Visible") somewhere but not sure.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var currentNode = Node.GetCurrent();
// Retrieve the latest N articles from the parent folder
var nodes = FindChildren(currentNode, t => (t.NodeTypeAlias.Equals("NewsArticle")));
var nodesOutput = nodes.OrderByDescending(n => n.GetProperty("newsDate").Value).Take(numberOfArticles);
newsRepeater.DataSource = nodesOutput;
newsRepeater.DataBind();
}
}
private static List<Node> FindChildren(Node currentNode, Func<Node, bool> predicate)
{
List<Node> result = new List<Node>();
var nodes = currentNode
.Children
.OfType<Node>()
.Where(predicate);
if (nodes.Count() != 0)
result.AddRange(nodes);
foreach (var child in currentNode.Children.OfType<Node>())
{
nodes = FindChildren(child, predicate);
if (nodes.Count() != 0)
result.AddRange(nodes);
}
return result;
}
Get only visible nodes using API
I have the following code which is working great apart from it's returning nodes that aren't published. Where would I need to tweak it ? I presume I need a .Where("Visible") somewhere but not sure.
I don't know the answer but 'Visible' is not related to published state, it's to do with having umbracoNaviHide set to true / false.
What verison of Umbraco are you using?
Rich
Sorry should have said 4.9.1.
Hey Ian,
I'm not doing enough coding these days, but is this relevant?
http://our.umbraco.org/wiki/reference/api-cheatsheet/difference-between-node-and-document
Rich
is working on a reply...