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.
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.
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))
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.
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.
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.
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 -
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.
Hi Mygel,
I will try to point you in the right direction, here you have some code for pagination.
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.
Hope this helps. If you have other questions, then keep asking, and I will try my best to help you out.
/Dennis
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
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
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.
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!
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
Thank you! And this works with the grid?
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.
is working on a reply...