I've slightly amended the news carousel (well, called it something else as I''m using it for staff updates rather than news on our intranet) - see attached file and I'm getting some very odd behavour - it may be because it's running on Umbraco v7 rather than v6, I'm not sure!
My template code
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@*
Basic Homepage news carousel, gets the last 5 items (by date) that are targeted for
this type of section page (inc homepage), and displays them in a bootstrap carousel
you would want to include things like sticky news items, auto expiry etc.
*@
@*
Package Bug - this works but the starterKit Packaged content looses the newsLocation
value on import, so we are using a simpler query to prove concepts
var allNews = Umbraco.TypedContentAtXPath("//ulgNewsItem")
.Where(x=>x.IsVisible()
&& x.GetPropertyValue<DateTime>("articleDate") < DateTime.Now
&& x.GetPropertyValue<string>("newsLocation").Split(new Char[]{','}, StringSplitOptions.RemoveEmptyEntries).Contains(Model.Content.Id.ToString()))
.OrderByDescending(x=>x.GetPropertyValue<DateTime>("articleDate")).Take(5);
*@
@{
var allNews = Umbraco.TypedContentAtXPath("//ulgNewsItem")
.Where(x=>x.IsVisible()
&& x.GetPropertyValue<DateTime>("articleDate") < DateTime.Now)
.OrderByDescending(x=>x.GetPropertyValue<DateTime>("articleDate")).Take(5);
Apologies for the scrambled content - I was expecting it to all display in "code" mode!
By failing to display, the "photo", date and headline disappears in the carousel so the < > navigation is at the top and nothing can be displayed.
Both times 5 news items are returned but in the version that works whichhas the dates 21/05/2015 - 1 of 1/06/2015 - 1 of 22/06/2015 - 2 of 25/06/2015 - 2 of 26/06/2015 - 2, class="item active" is set because one of the news items isFirst() == true
The version which fails to display the news items correctly occurs when I set one of the 22/06/2015 ones to 26/06/2015 (well, actually anything later than 22/06/2015) .
5 news items are returned but they are all class="item " news items isFirst() == false for each item.
var carouselItems = Umbraco.TypedContentAtXPath("//NewsItem")
.Where(x=>x.IsVisible()
&& x.GetPropertyValue<DateTime>("sortDate") < DateTime.Now)
.OrderByDescending(x=>x.GetPropertyValue<DateTime>("sortDate"));
We aren't currently using the .IsFirst() check, but just added it in to our partial and it worked as expected. Returning true for the first item. Tried it with a .Take(x) as well and still works. So not 100% sure why it wouldn't return one as IsFirst() as true.
Using that it returns 9 news items (all the live news items) and the active one (isFirst == true) is number 6 in the list so I can see why now doing the take(5) breaks it as the item that isFirst is not in there.
I'd made the assumption that the order was set by article date when this .OrderByDescending(x=>x.GetPropertyValue
Thanks for the idea of where to look though, I wouldn't have figured it out without playing with that.
uLocalGovMVC "news carousel"
I've slightly amended the news carousel (well, called it something else as I''m using it for staff updates rather than news on our intranet) - see attached file and I'm getting some very odd behavour - it may be because it's running on Umbraco v7 rather than v6, I'm not sure!
My template code
@* Basic Homepage news carousel, gets the last 5 items (by date) that are targeted for this type of section page (inc homepage), and displays them in a bootstrap carousel
you would want to include things like sticky news items, auto expiry etc. *@
@*
@{
}
@if (allNews.Any()) {
The working one has 9 staff updates article dated
21/05/2015 - 1 of 1/06/2015 - 1 of 22/06/2015 - 2 of 25/06/2015 - 2 of 26/06/2015 - 2 of
If I set one of the 22/06/2015 ones to 26/06/2015 (well, actually anything later than 22/06/2015) then the Staff updates fail to display correctly.
I've tracked it down to the fact that in the second scenario, no
Working html
Important info about car parking
Read on...
New look for insite
Read on...
Media summary - 15 to 26 June
Read on...
Staff visits
Read on...
Building Control is in the winning team
Read on...
None working html
Important info about car parking
Read on...
New look for insite
Read on...
Media summary - 15 to 26 June
Read on...
Staff visits
Read on...
Building Control is in the winning team
Read on...
We are using a derivative of this code for our site in V7 based off the Starter Kit.
Bit hard to work out what's going on as the forum has rather scrambled your code.
When you say they fail to display correctly, are they not displaying at all, or displaying in a way you wouldn't expect?
Apologies for the scrambled content - I was expecting it to all display in "code" mode!
By failing to display, the "photo", date and headline disappears in the carousel so the < > navigation is at the top and nothing can be displayed.
Both times 5 news items are returned but in the version that works whichhas the dates 21/05/2015 - 1 of 1/06/2015 - 1 of 22/06/2015 - 2 of 25/06/2015 - 2 of 26/06/2015 - 2, class="item active" is set because one of the news items isFirst() == true
The version which fails to display the news items correctly occurs when I set one of the 22/06/2015 ones to 26/06/2015 (well, actually anything later than 22/06/2015) .
5 news items are returned but they are all class="item " news items isFirst() == false for each item.
Seems odd.
We are using this as our selector code:
We aren't currently using the .IsFirst() check, but just added it in to our partial and it worked as expected. Returning true for the first item. Tried it with a .Take(x) as well and still works. So not 100% sure why it wouldn't return one as IsFirst() as true.
Using that it returns 9 news items (all the live news items) and the active one (isFirst == true) is number 6 in the list so I can see why now doing the take(5) breaks it as the item that isFirst is not in there.
I'd made the assumption that the order was set by article date when this .OrderByDescending(x=>x.GetPropertyValue
Thanks for the idea of where to look though, I wouldn't have figured it out without playing with that.
Glad I helped Steve.
is working on a reply...