Copied to clipboard

Flag this post as spam?

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


  • Brian 77 posts 251 karma points
    Jul 02, 2014 @ 08:25
    Brian
    0

    SmartBlog in version 7 - working but post list in wrong order

    Hi guys,

    I am using Smartblog in a version 7 website, the blog itself seems to be working fine however I am having an issue with the order of the blog posts as they are appearing in reverse order (oldest showing at the top of page 1 and so on).

    I have checked through the Post list partial (see code below) but am unable to find how the posts are sorted, please could someone help me with what I am sure is a simple issue!

    P.S. I have logged this twice on the Smartblog page however I have had no response from the developer

    Code being used for the post list page:

     

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @using System.Web.Mvc.Html;

    @using Umbraco.Web;

    @using umbraco.NodeFactory;

    @using Umbraco.Core.Models;

    @using Umbraco.Core.Dynamics;

    @{

        IPublishedContent blogRoot = Model.Content.AncestorOrSelf("SmartBlogBlog");

     

        List<IPublishedContent> results = new List<IPublishedContent>();

        System.Xml.XmlDocument document = new System.Xml.XmlDocument();

     

        document.Load(AppDomain.CurrentDomain.BaseDirectory + "/config/SmartBlog.config");

     

        bool useSummaryOnList = bool.Parse(document.GetElementsByTagName("useSummaryOnList")[0].InnerText);

     

        // Get posts by search query if specified, else just get all the posts.

        if(!string.IsNullOrEmpty(Request.QueryString["q"]))

        {

            Examine.SearchCriteria.ISearchCriteria filter = null;

            string searchTerm = "";

            results = SmartBlogLibraries.Helpers.Search.SearchBlog(out filter, out searchTerm).Select(x => ((IPublishedContent)Umbraco.Content(x.Id))).ToList();

        }

        else

        {

            results = ((IPublishedContent)CurrentPage).DescendantsOrSelf("SmartBlogPost").ToList();

        }

     

        // Refine posts by tag

        if (!string.IsNullOrEmpty(Request.QueryString["tag"]))

        {

            results = (from result in results

                       where (result.HasValue("smartBlogTags") && ((IList<string>)result.GetProperty("tag").Value.ToString().Split(',')).Contains(Request.QueryString["tag"]))

                       select result).ToList();

        }

     

        // Refine posts by author

        if (!string.IsNullOrEmpty(Request.QueryString["author"]))

        {

            results = (from result in results

                       where ((IList<string>)result.GetProperty("smartBlogAuthor").Value.ToString().Split(',')).Contains(Request.QueryString["author"]) ||

                               (Request.QueryString["author"] == document.GetElementsByTagName("defaultAuthor")[0].InnerText && result.GetProperty("author").Value.ToString().Length == 0)

                       select result).ToList();

        }

     

        // Refine posts by category

        if (!string.IsNullOrEmpty(Request.QueryString["category"]))

        {

            results = (from result in results

                       where ((IList<string>)result.GetProperty("smartBlogCategory").Value.ToString().Split(',')).Contains(Request.QueryString["category"])

                       select result).ToList();

        }

     

        // Make sure all results are smart blog posts and order by date

        results = results.Where(y => y.DocumentTypeAlias == "SmartBlogPost").OrderBy("smartBlogDate").ToList();

     

        // If there aren't any results, we notify the client.

        if(results.Count > 0)

        {

            // Calculate paging

            ushort page = 1;

            if (!ushort.TryParse(Request.QueryString["p"], out page))

            {

                page = 1;

            }

            ushort itemsPerPage = 6;

            int skip = (page - 1) * itemsPerPage;

            int resultCount = results.Count();

     

            // Render paging

            @Html.Raw(SmartBlogLibraries.Helpers.Listing.RenderPagination(page, resultCount, itemsPerPage))

     

            // Render posts

            <div class="postList">

                @foreach (IPublishedContent post in results.Skip(skip).Take(itemsPerPage))

                {

                    string author = post.GetProperty("smartBlogAuthor") != null && post.GetProperty("smartBlogAuthor").Value.ToString() != "" ?

                        post.GetProperty("smartBlogAuthor").Value.ToString() : 

                        document.GetElementsByTagName("defaultAuthor")[0].InnerText;

     

                    try

                    {

                        <div class="post">

                            <h3><a href="@Umbraco.NiceUrl(post.Id)">@post.Name</a></h3>

                            @if(useSummaryOnList)

                            {

                                <p>@Html.Raw(post.GetProperty("smartBlogSummary").Value.ToString())</p>

                            }

                            else

                            {

                                @Html.Raw(post.GetProperty("smartBlogBody").Value.ToString())

                            }

                            By <a href="?author=@author">@author</a> at @Convert.ToDateTime(post.GetProperty("smartBlogDate").Value.ToString()).ToString(SmartBlogLibraries.Helpers.DateTime.DateFormatNormal)

                        </div>

                    }

                    catch(Exception) {}

                }

            </div>

     

            // Render paging

            @Html.Raw(SmartBlogLibraries.Helpers.Listing.RenderPagination(page, resultCount, itemsPerPage))

        }

        else

        {

            <text>Unfortunately, no results were found for '@Request.QueryString["q"]' in @Model.Content.Name, try searching a higher level.</text>

        }

    }

  • Sara 2 posts 22 karma points
    Oct 15, 2014 @ 16:14
    Sara
    0

    Have you managed to sort this issue? I am experiencing the same problem :(

  • Brian 77 posts 251 karma points
    Oct 15, 2014 @ 16:18
    Brian
    0

    Hi Sara,

    If you check the other post for this you should find the solution there.  Apologies this is a vague answer but I can't remember the solution off the top of my head.

Please Sign in or register to post replies

Write your reply to:

Draft