var max = CurrentPage.Parent.Children.Where("Visible");
foreach (var relatedItems in CurrentPage.Parent.Children.Where("Visible").Random(3))
{
<h4>@relatedItems.Id => @relatedItems.Name</h4>
}
I tried;
var max = CurrentPage.Parent.Children.Where("Visible");
foreach (var relatedItems in CurrentPage.Parent.Children.Where("Visible").Random(3))
{
if (relatedItems.Name != Model.Content.Name)
{
<h4>@relatedItems.Id => @relatedItems.Name</h4>
}
}
Its works, but sometimes its only display two articles. I think the third article is hidden because of the if statement.
I'm stuck with this, any help would be appreciated!
How to show related articles?
Hi,
I want to display a random related articles inside the articles page. Everything works well, but I want to exclude also the
CurrentPage
.For example: I'm in the
Articles 1 Page
and I want to display only theArticles 2, Articles 3 & Articles 4
But in my case, the
Articles 1
is also shown.The Website structure.
Here's my code;
I tried;
Its works, but sometimes its only display
two articles
. I think the third article is hidden because of theif statement
.I'm stuck with this, any help would be appreciated!
Hey Jin,
You could simplify this with the use of
.Siblings
for example:Check out https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets for some more tips. It says v6 but is still relevant.
Hi Matt,
Thanks for your response.
But it keeps displaying the
Article 1 page
.My question is
while I'm in the Article 1 page
I don't want thearticle 1
shows in theRelated Articles
Problem;
the article 1 is showing in the Related Articles.
Hope I explain well :(
Regards,
Jin
Hi Matt,
Its working now, thanks to you :)
Alongside Siblings, you should really use an ID to compare rather than a name. You can do it in a lambda clause like so.
Model.Content.Sibings().Where(x => x.Id != Model.Content.Id)
If you're using Models Builder you can even typecast to ensure it's only Articles you get
Model.Content.Siblings<Article>()...
Hi Daniel,
It's working now :)
Thanks for your help!
is working on a reply...