I've been using Umbraco for a few months now so I'm starting to know my way around.
I've created a news page which works fine, then created a partial view to show the latest 4 items and everything is working fine. What I want to do is now get a little fancy....
On my news Item documentType I've created a true/false, what I want to do is if this is set to true, then have this as a featured post which shows at the top of the website as a highlighted/important information. if nothing is set to true then just display the latest.
I was just wondering if someone could point me in the right direction of where best to get started?
Welcome to the world of Umbraco!
I've been away from the forums for a while and haven't look at 8 in depth recently but this was very easy to achieve in 7 and I doubt things have changed that much.
The first step as you have identified is to add a property to your news item documentType that indicates if the post is featured or not.
The next step would be to create your component that is displayed at the top of the page. Notice I used the word component so I am assuming your would like this to be reusable in other areas of the site or be flexible enough to place where you want.
Take a look at macro partials in the documentation. What you would need to do is construct a query look for the News page and then grab its children with a filter that orders by featured then by date created / updated. This way, if an item is featured it will appear at the top of the list otherwise the filter will just have the newest news item at the top. All you need to do then is select the first item in the resulting collection and return it in whatever way seems fit.
That's the logical approach that is required. If you are still struggling later I can try and put together some example code for you this evening once I've finished work.
So this is my code which I have which shows in the features area, currently it just displays the latest and only shows 1. So I'm guessing I want to know how can I show the newsItem which is featured as true? and if nothing is true then it just shows the latest?
You'll have to double check around the syntax but basically it will order by featured values that are 1 at the top then order by the most recently created. If you have no featured items everything should be 0 in which case it will just filter by the latest date.
True/False featured item
Hello all,
I've been using Umbraco for a few months now so I'm starting to know my way around.
I've created a news page which works fine, then created a partial view to show the latest 4 items and everything is working fine. What I want to do is now get a little fancy....
On my news Item documentType I've created a true/false, what I want to do is if this is set to true, then have this as a featured post which shows at the top of the website as a highlighted/important information. if nothing is set to true then just display the latest.
I was just wondering if someone could point me in the right direction of where best to get started?
Thanks
Matt
Hi Matt,
Welcome to the world of Umbraco! I've been away from the forums for a while and haven't look at 8 in depth recently but this was very easy to achieve in 7 and I doubt things have changed that much.
The first step as you have identified is to add a property to your news item documentType that indicates if the post is featured or not.
The next step would be to create your component that is displayed at the top of the page. Notice I used the word component so I am assuming your would like this to be reusable in other areas of the site or be flexible enough to place where you want.
Take a look at macro partials in the documentation. What you would need to do is construct a query look for the News page and then grab its children with a filter that orders by featured then by date created / updated. This way, if an item is featured it will appear at the top of the list otherwise the filter will just have the newest news item at the top. All you need to do then is select the first item in the resulting collection and return it in whatever way seems fit.
That's the logical approach that is required. If you are still struggling later I can try and put together some example code for you this evening once I've finished work.
Hi Matt,
This query will help you.
// ParentID of News is 1100
var list = Umbraco.TypedContent(1100).DescendentsOrSelf
It will give you list first ordered by Featured items and then by created date is descending order.
Hope that helps you to solve the issue.
Regards,
Shaishav
Hey Matt,
You should try this code
Hi,
Thanks all for your reply.
So this is my code which I have which shows in the features area, currently it just displays the latest and only shows 1. So I'm guessing I want to know how can I show the newsItem which is featured as true? and if nothing is true then it just shows the latest?
It depends. A boolean true/false should evaluate to 1 or 0 so you could add an additional filter along the lines of:
You'll have to double check around the syntax but basically it will order by featured values that are 1 at the top then order by the most recently created. If you have no featured items everything should be 0 in which case it will just filter by the latest date.
Hi,
I would appreciate if someone could show me some code which I would be able to use and hopefully tweak where possible.
I'm not a great coder, still learner as I go :)
Thanks
Hi Matt,
How are you building your site? Are you using visual studio or are you building it all from within Umbraco?
Thanks,
Nik
Hi Nik,
A bit of both really I guess, I created all the templates and partial views in umbraco. but use visual studio to edit any code.
Thanks
Hi Matt,
you can have a look at this link https://youtu.be/mLY7asEoQak
Hi,
Anybody able to share anything with this?
I tried the below but doesn't seem to work;
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.