Right now I print a list of the first year's children seeing as thats how far I've come.
The Content structure looks like this:
Articles
2013
Article 1
Article 2
2014
Article 1
Article 2
And the code I have so far looks like this:
var root = Model.AncestorOrSelf(1).Down(1);
var selection = root.Children.OrderBy("homepageArticleDate desc");
@foreach (var item in selection)
{
here I do stuff..
}
Now what I need to do is run through all of the years (I have from 2002-2014) and show their children (a hard way to say every single article ever written).
And can I then still sort them from their descending date?
Thanks for the quick answer man, great to have friendly people like you around!!!
I added the using but now I get the following error instead:
error CS1061: 'System.Collections.Generic.List' does not contain a definition for 'Children' and no extension method 'Children' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?)
What may be the reason for this, do you have any idea?
I tried what you suggested, but I now receive another error, how lucky I am :D
This is the code for the full ArticleList.cshtml macro I have so far:
@using umbraco.MacroEngines;
@using umbraco.cms.businesslogic.media;
@using umbraco.BusinessLogic;
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
List<DynamicNode> root = Model.AncestorOrSelf(1).Descendants("HomepageArticle").OrderBy("homepageArticleDate desc").Items;
int pageSize; // How many items per page
int page; // The page we are viewing
/* Set up parameters */
if (!int.TryParse(Parameter.PageSize, out pageSize))
{
pageSize = 20;
}
if (!int.TryParse(Request.QueryString["page"], out page))
{
page = 1;
}
/* This is your basic query to select the nodes you want */
var olderArticles = root;
int totalArticles = olderArticles.Count();
int totalPages = (int)Math.Ceiling((double)totalArticles / (double)pageSize);
/* Bounds checking */
if (page > totalPages)
{
page = totalPages;
}
else if (page < 1)
{
page = 1;
}
}
<ul>
@foreach (var item in olderArticles.Skip((page - 1) * pageSize).Take(pageSize))
{
if (item.HasValue("homepageArticleImage"))
{
<li class="article-list">
<div class="row">
<div class="col-md-4 text-right">
<a href="@item.Url"><img src="@item.Media("homepageArticleImage", "umbracoFile")"></a>
</div>
<div class="col-md-8">
<h8 class="darkblue"><a href="@item.Url">@item.homepageArticleTitle</a></h8><br />
<i>af @item.homepageArticleByline </i> <br />
<p>@item.homepageArticleTeaser </p>
<div style="font-size: 11px">@item.homepageArticleDate.ToShortDateString()</div>
</div>
</div>
<div class="breaker"></div>
</li>
}else
{
<li class="article-list" style="background-color: #f5f5f5; padding: 20px; margin-bottom: 10px;">
<div class="row">
<div class="col-md-12">
<h8 class="darkblue"><a href="@item.Url">@item.homepageArticleTitle</a></h8><br />
<i>af @item.homepageArticleByline </i> <br />
<p>@item.homepageArticleTeaser </p>
<div style="font-size: 11px">@item.homepageArticleDate.ToShortDateString()</div>
</div>
</div>
</li>
}
}
</ul>
<div class="text-center">
<ul class="paging">
@for (int p = 1; p < totalPages + 1; p++)
{
string selected = (p == page) ? "selected" : String.Empty;
<li class="@selected"><a href="?page=@p" title="Go to page @p of results">@p</a></li>
}
</ul>
</div>
This produces the following error:
error CS1061: 'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'homepageArticleTitle' and no extension method 'homepageArticleTitle' accepting a first argument of type 'umbraco.MacroEngines.DynamicNode' could be found (are you missing a using directive or an assembly reference?)
I really hope you can help.. I am trying everything, and it just seems like umbraco is against me :(
Hey, yeah I have had it working with paging, but it could only take the first year.
It was included in the macro all along, but that's not where i complains.. its working fine if I do like this:
var root = Model.AncestorOrSelf(1).Down(1);
var selection = root.Children.OrderBy("homepageArticleDate desc");
@foreach (var item in selection)
{
here I do stuff..
}
But yeah It only prints all the children of one of the years, and I need all children of all of the years in one big list
I imagine that is goes wrong with the root = xx,
But Ive tried all your suggestions and about 10 other and nothing works..
I'm sorry I might not have explained my self well enough :/
I have approx. 4.000 articles spread out under years in the content, like 2002,2003,2004 and so on..
I would like it to be like this:
You go to "Articles"
There will be a sub menu like: 2002,2003,2004 and so on, and it then shows all the Articles from 2014 with pagination on it, when you enter, and have pagination accordingly on every other year's article list...
Does that make any sense? and if so, can you help :D?
Thanks for your time, it really is much appreciated!
What I have so far:
I've made two razor scripts. ArticleListMenu and ArticleList
The ArticleListMenu is fairly straight forward for now:
var root = Model.AncestorOrSelf(1).DescendantsOrSelf("ArticleArchive").First();
foreach(var page in root.Children)
{
<a href="@page.Url">@page.Name</a>
}
The ArticleList is a bit more complex (for me anyway :):
@{
var root = Model.AncestorOrSelf(1).DescendantsOrSelf("ArticleArchiveYear").First();
var articles = root.Children.OrderBy("homepageArticleDate desc, homepageArticleDate");
int pageSize; // How many items per page
int page; // The page we are viewing
if (!int.TryParse(Parameter.PageSize, out pageSize)){ pageSize = 20; }
if (!int.TryParse(Request.QueryString["page"], out page)){ page = 1; }
int totalArticles = articles.Count();
int totalPages = (int)Math.Ceiling((double)totalArticles / (double)pageSize);
if (page > totalPages) { page = totalPages; }
else if (page < 1) { page = 1; }
}
<ul>
@foreach (var item in articles.Skip((page - 1) * pageSize).Take(pageSize))
{
if (item.HasValue("homepageArticleImage"))
{
<li class="article-list">
<div class="row">
<div class="col-md-4 text-right">
<a href="@item.Url"><img src="@item.Media("homepageArticleImage", "umbracoFile")"></a>
</div>
<div class="col-md-8">
<h8 class="darkblue"><a href="@item.Url">@item.homepageArticleTitle</a></h8><br />
<i>af @item.homepageArticleByline </i> <br />
<p>@item.homepageArticleTeaser </p>
<div style="font-size: 11px">@item.homepageArticleDate.ToShortDateString()</div>
</div>
</div>
<div class="breaker"></div>
</li>
}else {
<li class="article-list" style="background-color: #f5f5f5; padding: 20px; margin-bottom: 10px;">
<div class="row">
<div class="col-md-12">
<h8 class="darkblue"><a href="@item.Url">@item.homepageArticleTitle</a></h8><br />
<i>af @item.homepageArticleByline </i> <br />
<p>@item.homepageArticleTeaser </p>
<div style="font-size: 11px">@item.homepageArticleDate.ToShortDateString()</div>
</div>
</div>
</li>
}
}
</ul>
<div class="text-center">
<ul class="paging">
@for (int p = 1; p < totalPages + 1; p++)
{
string selected = (p == page) ? "selected" : String.Empty;
<li class="@selected">
<a href="?page=@p" title="Go to page @p of results">@p</a>
</li>
}
</ul>
</div>
The menu of all years with articles in them, are displayed 2014 - 2013 - 2012, and so on, as it should.
I've gotten it to print out the first year of the list in the ArticleList razor script, as I had before, with pagination (almost).
Now here is where it gets tricky for me:
How do I link every ArchiveYear to a list of that year's content, showing the list with pagination of course?
And also;
What is wrong with my pagination? It shows a list of 20 articles, and a pagination of 20 pages from 1-20 as links, but when I click that pagenumber - it shows the same list as page 1, on all the other 19 pages, as if it can't prober load the other articles..
List of all childrens children
Hi guys!
Right now I print a list of the first year's children seeing as thats how far I've come.
The Content structure looks like this:
And the code I have so far looks like this:
Now what I need to do is run through all of the years (I have from 2002-2014) and show their children (a hard way to say every single article ever written).
And can I then still sort them from their descending date?
Every help I can get would help, thank you !
Hi David,
You could do something like this
Hope this helps
//fuji
Hey fuji
Sorry it has taken me so long to write you back.. I have never quite understood but for some reason when I use List
I've tried to google it, but I have had no luck in getting to know what that means, or how to solve it :(
My code now looks like this:
Please help me :) thank you
hi David,
Remember to add the
Thanks for the quick answer man, great to have friendly people like you around!!!
I added the using but now I get the following error instead:
What may be the reason for this, do you have any idea?
Remove the var selection = root.children
Hey Fuji
I tried what you suggested, but I now receive another error, how lucky I am :D
This is the code for the full ArticleList.cshtml macro I have so far:
This produces the following error:
I really hope you can help.. I am trying everything, and it just seems like umbraco is against me :(
Hi David,
Looks like you are working with a paging now right ?
In your first post you wanted to display article 1 & 2 is any is visible. Did you get this part working ?
Hey, yeah I have had it working with paging, but it could only take the first year.
It was included in the macro all along, but that's not where i complains.. its working fine if I do like this:
But yeah It only prints all the children of one of the years, and I need all children of all of the years in one big list
I imagine that is goes wrong with the root = xx, But Ive tried all your suggestions and about 10 other and nothing works..
Sorry am getting a bit confused, you basically want to display all children (Article) from year 2013, 2014 etc .. ?
But when you are on each individual year you want to make a paging right?
I'm sorry I might not have explained my self well enough :/
I have approx. 4.000 articles spread out under years in the content, like 2002,2003,2004 and so on..
I would like it to be like this:
You go to "Articles"
There will be a sub menu like: 2002,2003,2004 and so on, and it then shows all the Articles from 2014 with pagination on it, when you enter, and have pagination accordingly on every other year's article list...
Does that make any sense? and if so, can you help :D?
Hi David
So just to clarify and and sound like a stuck record.
You would like the page to show a menu of the years... When you get to the page you see all articles listed, and paged, and in date descending order.
If you click on one of the submenu date items you only get that years items, paged and in date descending order? Sort of like a filter?
Or am I totally wrong?
You are exactly right!
Can you help me with that?, How should I go about it? does it need more than one macro or?
Hey David yes you will need 2 razor scripts to do this. I am. One that will form the navigation and one that will be your listing.
Hey Peter,
Thanks for your time, it really is much appreciated!
What I have so far:
I've made two razor scripts. ArticleListMenu and ArticleList
The ArticleListMenu is fairly straight forward for now:
The ArticleList is a bit more complex (for me anyway :):
The menu of all years with articles in them, are displayed 2014 - 2013 - 2012, and so on, as it should. I've gotten it to print out the first year of the list in the ArticleList razor script, as I had before, with pagination (almost).
Now here is where it gets tricky for me:
How do I link every ArchiveYear to a list of that year's content, showing the list with pagination of course?
And also; What is wrong with my pagination? It shows a list of 20 articles, and a pagination of 20 pages from 1-20 as links, but when I click that pagenumber - it shows the same list as page 1, on all the other 19 pages, as if it can't prober load the other articles..
Thanks again for taking the time to read this!!!
hey man, did you resolve this?? i need something quite similar
is working on a reply...