Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nick 95 posts 492 karma points
    Feb 25, 2023 @ 09:38
    Nick
    0

    Nest news article nodes within date folder

    Hi,

    Wondered if anybody could help, I have a list of news articles which are nested individual below a page node, they render on the site fine, but because of the amount of articles I want to render them within dte folders like this:

    enter image description here

    But when I do the news artciles dont't render on the page anymore, there are no error messages, here is the code on the page, can anybody help please:

    @using Umbraco.Cms.Web.Common.PublishedModels;
    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.NewsListingsPage>
    @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
    @{
        Layout = "Master.cshtml";
        int currentPage = 1;
        var pageNo = Context.Request.Query["page"];
        var pageSize = (int)(Model.PageCount!=null&& Model.PageCount > 0 ? Model.PageCount : 6);
        var TotalItems = Model?.Children<NewsArticlePage>();
    
        var page = 1;
        int.TryParse(Context.Request.Query["page"], out page);
        var articles = TotalItems.Skip((page - 1) * pageSize).Take(pageSize).OrderByDescending(x => x.PublishedDate);
        var totalPages = (int)Math.Ceiling((double)TotalItems.Count() / (double)pageSize);
    
        if (page > totalPages)
        {
            page = totalPages;
        }
        else if (page < 1)
        {
            page = 1;
        }
    }
    <!-- News Start -->
    <div class="section blog-section section-padding">
        <div class="container">
            <!-- News Grid Wrap Start -->
            <div class="blog-grid-wrap">
                @Model.Value("generalContent")
                <div class="row">
                    @if (articles != null && articles.Any())
                    {
                        foreach (var article in articles)
                        {
                            <div class="col-lg-4 col-md-6">
                                <!-- Single Blog Start -->
                                <div class="single-blog">
                                    <div class="blog-img">
                                        <a href="@article?.Url()">
                                            <img src="@article?.ListingImage?.GetCropUrl(width:416,height:251)" alt="" />
                                        </a>
                                        <div class="top-meta">
                                            <span class="date"><span>@article?.PublishedDate?.ToString("dd")</span>@article?.PublishedDate?.ToString("MMM")</span>
                                        </div>
                                    </div>
                                    <div class="blog-content">
                                        <div class="blog-meta">
                                            <span>
                                                <i class="fas fa-user"></i>
                                                <a href="#">@article?.CreatorName()</a>
                                            </span>
                                        </div>
                                        <h3 class="title">
                                            <a href="@article?.Url()">
                                                @(Html.Raw(article?.Name))
                                            </a>
                                        </h3>
                                        <p>
                                            @(article?.ListingSummary)…
                                        </p>
                                    </div>
                                    <div class="blog-btn">
                                        <a class="blog-btn-link" href="@article?.Url()">
                                            Read Full Article
                                            <i class="fas fa-long-arrow-alt-right"></i>
                                        </a>
                                    </div>
                                </div>
                                <!-- Single Blog End -->
                            </div>
                        }
    
                    }
                </div>
                @if (totalPages > 1)
                {
                    <!-- Pagination Start -->
                    <div class="pagination-wrap">
                        <ul class="pagination justify-content-center">
    
                            <li class="page-item @(page > 1?"":"disabled")">
                                <a href="?page=@(page-1)">
                                    <span class="page-link"><i class="flaticon-back"></i></span>
                                </a>
                            </li>
    
                            @for (int p = 1; p < totalPages + 1; p++)
                            {
                                <li class="page-item @(page==p?"active":"")">
                                    <a class="page-link" href="?page=@p">@p</a>
                                </li>
                            }
                            <li class="page-item @(page < totalPages?"":"disabled")">
    
                                <a class="page-link" href="?page=@(page+1)">
                                    <i class="flaticon-next"></i>
    
                                </a>
    
                            </li>
                        </ul>
                    </div>
                }
                <!-- Pagination End -->
            </div>
            <!-- Blog Grid Wrap End -->
        </div>
    </div>
    <!-- News End -->
    

    Kind regards

    Nick

  • Dennis 75 posts 398 karma points MVP 2x
    Feb 28, 2023 @ 13:35
    Dennis
    100

    Hi Nick,

    I notice on line 9 of your code snippet, you use Model?.Children<NewsArticlePage>(). Children are only the pages directly below your overview page. If you want to get the news detail pages, you'll want to use Model?.Descendants<NewsArticlePage>().

    Kind regards,
    Dennis

  • Nick 95 posts 492 karma points
    Feb 28, 2023 @ 14:04
    Nick
    0

    Many thanks Dennis,

    Just tried that and it works great, many thanks

    Nick

Please Sign in or register to post replies

Write your reply to:

Draft