@{ //moving to the page with the child items //if you are on the blog page with children you can get the children by using Model.content.Children() var home = Model.Content.AncestorsOrSelf("Home").First(); var blogs= home.Descendants("Blog").First(); }
@foreach (var blog in blogs.Descendants("BlogPost").Where(x => x.GetPropertyValue("type").Equals("funny"))) { // do things with blogpost }
If your blogpost is structure under blog I think that you could do something like this:
@{ //moving to the page with the child items //if you are on the blog page with children you can get the children by using Model.content.Children() var home =Model.Content.AncestorsOrSelf("Home").First(); var blogs= home.Descendants("Blog").First(); }
@foreach(var blog in blogs.Children.Where(x => x.GetPropertyValue("blogCategory").Equals("funny"))) { // do things with blogpost }
I assume that blogCategory is the alias of the field where the user should choose category for each post.
Displaying Blog Posts
Hello All,
I am trying to display blog posts with a certain property that I have assigned them (using a custom drop down type i created).
I have used this code in a previous project.
Is there anyway to modify the following to search for blog posts with a property of "funny" or "romantic" for example.
@foreach(var page in CurrentPage.DescendantsOrSelf("BlogPost").OrderBy("CreateDate desc"))
{
//Do Stuff
}
Kind regards.
Hi James,
CanĀ“t you do something simlar what you did on on the category. http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/57313-Searching-for-a-category?p=0#comment195615
Hope this helps,
/Dennis
I'm actually having trouble with that code.
The page loads once I have put in the custom property type "Blog Category" and "Funny".
Inside the code block I put what i want to be displayed (the blog post structure). But nothing loads? I have tried to modify the code but to no avail.
The structure of my site is:
Home > Blog > Blog Posts
I am trying to render the code on the "Home" Page template.
So far:
@{
//moving to the page with the child items
//if you are on the blog page with children you can get the children by using Model.content.Children()
var home = Model.Content.AncestorsOrSelf("Home").First();
var blogs= home.Descendants("BlogPost").First();
}
@foreach (var blog in blogs.Descendants("BlogPost").Where(x => x.GetPropertyValue("Blog Category").Equals("Funny")))
{
<span class="date">
29 <small>JUN 2014</small>
</span>
}
Page Loads fine but nothing displays so its not pulling anything through?
Kind regards.
Hi James,
If your blogpost is structure under blog I think that you could do something like this:
I assume that blogCategory is the alias of the field where the user should choose category for each post.
Hope this helps,
/Dennis
Thanks Dennis,
Again something very simple. One of these days I'll learn to solve this sort of stuff on my own. :)
Your code was correct. My assumption that my Alias was blog category was incorrect however.
My alias was in fact: blogPostCategory.
Everything now works. Including the code in the previous topic.
Kind regards,
J
is working on a reply...