When I'm on the Article page all I want to do is have a button that has a "Newer Post" and "Older Post" link but I can't get this to work and I've tried a numerous amount of ways/guesses. This is one of the ways I was trying to get the newer post Url.
FYI: date is the alias of a datepicker on my Article node
var newer = Model.AncestorOrSelf(1).Descendants().Where("NodeTypeAlias == \"Article\" && date > Model.date").OrderBy("date desc").First();
With this code I am getting the following error message:
Error Loading Razor Script (file: Article Pager) The binary operator GreaterThan is not defined for the types 'System.Object' and 'System.Object'. at System.Linq.Expressions.Expression.GetUserDefinedBinaryOperatorOrThrow(ExpressionType binaryType, String name, Expression left, Expression right, Boolean liftToNull)
The error is quite extensive, telling me I have a problem at line 4 in my cshtml file which is where I've declared the newer variable.
I've also tried mixing up the .Where() to include the Article NodeTypeAlias and CreateDate > Model.CreateDate as well as CreateDate > \"" + Model.CreateDate + "\" but I've had no luck. I'd really like to filter by the date if at all possible (vs using CreateDate).
You could try something like this and see if it does any difference.
var newer =Model.AncestorOrSelf(1).Descendants().Where("NodeTypeAlias == @0 && date > @1", "Article",Model.date).OrderBy("date desc").First();
You could try this one. I found inspiration here:
var date = DateTime.Now.ToString("ddMMyyyy"); var currentPageDate = Model.Date.ToString("ddMMyyyy"); var newer = Model.AncestorOrSelf(1).Descendants("Article").Where("date > @1",currentPageDate).OrderBy("date desc").First();
You rock!! Thank you so much for your help & the other forum topic thread. I'm curious why the way I first wrote it wasn't working. Below ended up being my final code. I elimated the .First() because I was getting an error since there weren't any older posts. I used the .Count() to check if I needed my buttons. I really appreciate the help! I was stuck on this one. Thank you!
Get next article with date > model.date
I'm stuck and I appreciate any and all help I can get. I'm using Umbraco v4.11.10.
I'm using date folders for a blog so my Content tree structure looks like this:
Home
- 2013
- - 07
- - - Article
- 2014
- - 02
- - - Article
When I'm on the Article page all I want to do is have a button that has a "Newer Post" and "Older Post" link but I can't get this to work and I've tried a numerous amount of ways/guesses. This is one of the ways I was trying to get the newer post Url.
FYI: date is the alias of a datepicker on my Article node
With this code I am getting the following error message:
Error Loading Razor Script (file: Article Pager) The binary operator GreaterThan is not defined for the types 'System.Object' and 'System.Object'. at System.Linq.Expressions.Expression.GetUserDefinedBinaryOperatorOrThrow(ExpressionType binaryType, String name, Expression left, Expression right, Boolean liftToNull)
The error is quite extensive, telling me I have a problem at line 4 in my cshtml file which is where I've declared the newer variable.
I've also tried mixing up the .Where() to include the Article NodeTypeAlias and CreateDate > Model.CreateDate as well as CreateDate > \"" + Model.CreateDate + "\" but I've had no luck. I'd really like to filter by the date if at all possible (vs using CreateDate).
Thanks for any help! - Blake
Hi Blake,
You could try something like this and see if it does any difference.
You could try this one. I found inspiration here:
http://our.umbraco.org/forum/developers/razor/26022-Razor,-Where-%28DatetTime-Greater-Than-Or-Equal-DateX-%29
Hope this help you further.
/Dennis
You rock!! Thank you so much for your help & the other forum topic thread. I'm curious why the way I first wrote it wasn't working. Below ended up being my final code. I elimated the .First() because I was getting an error since there weren't any older posts. I used the .Count() to check if I needed my buttons. I really appreciate the help! I was stuck on this one. Thank you!
is working on a reply...