Copied to clipboard

Flag this post as spam?

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


  • Mygel 9 posts 40 karma points
    Jun 14, 2014 @ 20:06
    Mygel
    0

    Create Pagination

    Hey Fourm, 

    The last couple of says I have hit a stump which I can't seem to figure out. I am trying to create a pagnation feature on my website.

    What pagination looks like: http://cdn.onextrapixel.com/wp-content/uploads/2009/06/pagination.jpg

    I am using Foundation 5 Pagination markup which is:
    http://pastebin.com/B3EudwXp

    I want to load 6 articles on every page. Every 6 articles I create will generate the next page number and add it to the list. I have been using Razor but I am struggling with this portion and would like some advice or links to point me to the right direction. I am still getting the hang of all this information but this would really help me move along.

    Quick questions:
    I see people using code like this -

    foreach (var group in items.Children.InGroupsOf(3)) {
    foreach (var item in group)  {
    <li><a href="#">@item.Name</a></li>
     }
    }

     


    Instead of items, they use Model or Umbraco. Can someone explain or link me to why it seems I can only use Currentpage and nothing else?

    Another question I have is in the code above, how can I generate three <a href="#">@item.Name</a> and then inject an <li> to surround all of them rather than having 3 <li><a href="#">@item.Name</a></li> seperate Li tags?

    Thanks hopefully I can solve a few of these issues. 

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 15, 2014 @ 21:09
    Dennis Aaen
    0

    Hi Mygel,

    I will try to point you in the right direction, here you have some code for pagination.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "null";
        int pageSize = 2; // How many items per page
        int page; // The page we are viewing

        /* Set up parameters */

        if (!int.TryParse(Request.QueryString["page"], out page))
        {
            page = 1;
        }

        /* This is your basic query to select the nodes you want */

        var nodes = Model.Content.Children.Where(x => x.DocumentTypeAlias == "NewsArticle").OrderBy(x=>x.CreateDate);

        int totalNodes = nodes.Count();
        int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize);

        /* Bounds checking */

        if (page > totalPages)
        {
            page = totalPages;
        }
        else if (page < 1)
        {
            page = 1;
        }
    }

    In this example I creates pagination for special document type called NewsArticle you will need to make some changes to the code to match your case, but I think this is can be a good starting point for you.

    To the other question you have about  how you can generate three <a href="#">@item.Name</a> and then inject an <li> to surround all of them rather than having three li´s, something like this should do it.

    foreach(var group in items.Children.InGroupsOf(3)){
       
    <li>    
           
    @
    foreach(var item in group)  {
               
    <a href="#">@item.Name</a></li>
           
    }
       
    </li>
    }

    Hope this helps. If you have other questions, then keep asking, and I will try my best to help you out.

    /Dennis

  • Phil 3 posts 23 karma points
    Jul 23, 2014 @ 16:25
    Phil
    0

    Hi Dennis, 

    I'm trying to add pagination to a basic loop. I'm tackling your code but not finding it straight forward, maybe you could help me out? How do I actually set up a link to next or previous pages? Here is my simple loop: 

        @foreach (var example in CurrentPage.Children.OrderBy("createDate descending").Take(8)) 

        {

        //Do Stuff//

        }

    Phil 

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 23, 2014 @ 17:08
    Dennis Aaen
    0

    Hi Phil,

    Try to see Dan´s method how to create a paging in Umbraco on this thread.

    http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/54792-Item-Paging-in-Umbraco

    Hope this helps,

    /Dennis

  • Charl 1 post 21 karma points
    May 23, 2015 @ 23:11
    Charl
    0

    Hi Guys, I am new to umbraco and currently in the process of wiring my website template with umbraco. I have a blog feature which I would like to create pagination for my posts on my blog's main page. So far I am currently using partial view macro to list my Blog post name, blog photo, intro and date. The macro code is as follows and I would like to add pagination to this code by showing 8 posts per page.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

        

        @{

       //Fetch the blogposts from a certain node id

       var blogPosts = Umbraco.Content(1315);

     

      foreach(var blogPost in blogPosts.Children()){

             

            <h2><a href="@blogPost.NiceUrl()">@blogPost.Name</a></h2>

    <a href="@blogPost.NiceUrl()" rel="Post"><img class="blogphoto" src="@blogPost.NiceUrl()" alt="Marine"></a>        

            <p>@Umbraco.Truncate(blogPost.content, 200, true)</p>

    <div class="date">@blogPost.CreateDate.ToLongDateString()</div>

    }         

    }    

    I would love to know if any one could please be so kind to assist me with this. 

  • Nelson 94 posts 246 karma points
    Mar 15, 2016 @ 09:54
    Nelson
    0

    Hello Charl,

    I'm working with a similar feature as you did before, did you found out a solution? If so, would it be possible to share it with me?

    Thank you very much!

  • Eric Schrepel 161 posts 226 karma points
    Mar 24, 2016 @ 22:57
    Eric Schrepel
    0

    This article has the best code, and relevant to Umbraco 6+ (we use 7.4.2). We removed the code near the end which creates a bunch of numbered page links, and left just the "< Previous" and "Next >" links.

    https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/54792-Item-Paging-in-Umbraco

  • Nelson 94 posts 246 karma points
    Mar 29, 2016 @ 07:03
    Nelson
    0

    Thank you! And this works with the grid?

  • Eric Schrepel 161 posts 226 karma points
    Mar 29, 2016 @ 16:09
    Eric Schrepel
    0

    I believe so; we use the grid feature intermittently (some users like it, others just use straight rich-text content fields), and whether this code is in a partial view macro or a template, seems to work just fine.

Please Sign in or register to post replies

Write your reply to:

Draft