I can't find anywhere on Umbraco CMS very useful option which I have used before while using CMS like Drupal and Joomla. I kindly ask you to first look at the photo in attachment.
As you can see I would like to have option which will limit number of displayed articles in list. For example I would like to see 10 articles per page. Is this possible on Umbraco CMS because I cant find it anywhere under Macros?
Any help is appreciated and many thanks in advance for prompt reply!
Adi
<xsl:template match="/"> <xsl:variable name="about" select="umbraco.library:GetXmlNodeById('1067')"/><!-- Here is the NodeId from here you are pulling all the list of about -->
<xsl:variable name="itemsToDisplay" select="10"/> <!-- Number of items to display per page --> <xsl:variable name="numberOfItems" select="count($about/*[@isDoc][not(umbracoNaviHide =1)])"/> <xsl:variable name="jump" select="$itemsToDisplay * $pageNumber" />
<xsl:param name="currentPage"/> <xsl:variable name="about" select="umbraco.library:GetXmlNodeById('2343')"/><!-- Here is the NodeId from here you are pulling all the list of about -->
<xsl:variable name="itemsToDisplay" select="2"/> <!-- Number of items to display per page --> <xsl:variable name="numberOfItems" select="count($about/*[@isDoc][not(umbracoNaviHide =1)])"/> <xsl:variable name="jump" select="$itemsToDisplay * $pageNumber" />
I use Textapges all the time. Is it possible to simply update this code with code you suggested? This would be almost perfect solution for my template..
Hi Adi
There is another option if you are using Razor Views. The code below is pasted from the "Articles" template in the Standard Website Starter Kit (MVC version) and seems to work ok for me on v 6.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = "SW_Master.cshtml";
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;
}
which is showing list only if there is some content on current page. #code1 is showing only fixed value.
Is it possible to update #code1 so it could show list only if there is some content on current page, same as it is defined on #code2?
Ofcourse, I already have many articles which I have added long-time ago in back end.
Your code is working great except that Pagination.xslt always pulls data only from one node '1303' and that is issue for me. Your code worked very good until I didn't modify this part
[#code2] works really good and it is showing list only if there is some data (it doesn't use fixed value '1303' as [#code1] which is good). That is biggest advantage of [#code2]
[#code1] on the other side is showing only values from node '1303' which is not good and it is always shown on every page that uses Template 'Textpage'. For example, [#code2] also shows on every article that uses Template 'Textpage' but if there is no data, it doesn't shows anything which is great. Your code [#code1] has great advantages: it splits 10 articles per page, adds numeration of pages, creates links but it is only missing one more advantage that [#code2] has, which I describe above.
I hope I exaplained it correctly, If I need to answer anything else please don't hasitate to tell me.
Am getting a bite confused with [#code1][#code2]/!!!
Anyways looks like code1 is working as you expected so this is one thing. Now you want to do the same thing with code 2 right? If so then it will be something like
<xsl:variablename="items"select="$currentPage/ancestor-or-self::* [@isDoc and @level = 2]/* [@isDoc][not(umbracoNaviHide) != '1'][bodyContent !='']"/>
I have also becomed confused with codes at the end;) but I had no way to describe the issue, this way via forum.
I have link of my website which I would like to send you so you could see it live and difference between [#code1] and [#code2] because I simply have no way to explain it via forum. Please send me your e-mail or perhaps if I could send you pm via twitter or something like that.
Separating 10 articles per page?
Hello,
I can't find anywhere on Umbraco CMS very useful option which I have used before while using CMS like Drupal and Joomla. I kindly ask you to first look at the photo in attachment.
As you can see I would like to have option which will limit number of displayed articles in list. For example I would like to see 10 articles per page. Is this possible on Umbraco CMS because I cant find it anywhere under Macros?
Any help is appreciated and many thanks in advance for prompt reply! Adi
Hi Adi,
For some reason I couldn't write a comment on the other post, so you will get it here.
Try this one, I get no error when I save this version.
Hope it will work for you too.
/Dennis
Hi Weird i get the same issue and cant reply on the other threat. :)
Anyways sorry was my mistake where i commented the first part of the variable.
instead of
@Dennis however the loop here should be $about but its on mine again!
It should get you working now, i have just tried the code myself.
You can also add a Next or Previous Page url to your paging.
//Fuji
Hi Dennis,
I have used code you suggested from last post on this thread but unforunately I get this error
I don't understand why only on my website pageNumber isn't defined and or your exapmle it is working fine.. What am I doing wrong?
Best regards, Adi
Hello Fuji,
thank you for promt reply and fast switching to this topic, I really appreciate it.
I will try you suggestion as soon as find out why I see error which I have described in post above.
All the best, Adi
Hi Adi,
From the error you posted before looks like you are not using the code properly.
Can you try this please ?
I just tried that and it worked for me.
//Fuji
Hello Fuji,
yes, you were riht, I noticed the changes you made in your code and now I understand what was the (simple) issue;(
However, I have good news, code is working but I will have to make some adjustments in order to achieve what I really need on my template.
This is the code which shows active articles on every Textpage of my template.
I use Textapges all the time. Is it possible to simply update this code with code you suggested? This would be almost perfect solution for my template..
All the best, Adi
Hi Adi,
If you want to display only doc with a specific DocType then try something
Hope this is what you are trying to achieve here.
//fuji
Hi Adi There is another option if you are using Razor Views. The code below is pasted from the "Articles" template in the Standard Website Starter Kit (MVC version) and seems to work ok for me on v 6.
Hello Fuji,
I don't think I explained it on the best way to you. Please see screenshot bellow:
Can you help me update this code
in order to have pagination , 10 articles per page?
Thanks, Adi
Hi Adi,
By Active you mean be clickable from the list if so update this part and it should get you working.
However if you want an active class on the current paging try this
Hi Graeme,
thank you for posting very clean and useful Razlor example code but this time I decided to use XSLT.
All the best, Adi
Hello Fuji,
good news: code you suggestet is working successufully and now I have active links that are leading to articles.
However, I am still facing the issue I have described earlier which is giving me troubles. Please note that this is the current code (#code1):
and this is the part of #code1 which is giving me troubles
On my template, I have this default example code (#code2)
which is showing list only if there is some content on current page. #code1 is showing only fixed value. Is it possible to update #code1 so it could show list only if there is some content on current page, same as it is defined on #code2?
Greetings, Adi
Hi Adi,
So you want to display only the nodes where there is Content in it right ?
You can modify the first code to this
Hi Fuji,
thank you very much for prompt reply.
I did as you suggested:
but result is this
so now I can't see any items on the list?
Greetings, Adi
Hi Adi,
Yes you wont see any items since this field is empty. In the example code i sent you before am using a bodyContent as umbraco field.
Have you tried adding something to this field in the back end ?
Hello Fuji,
Ofcourse, I already have many articles which I have added long-time ago in back end. Your code is working great except that Pagination.xslt always pulls data only from one node '1303' and that is issue for me. Your code worked very good until I didn't modify this part
[#code2] works really good and it is showing list only if there is some data (it doesn't use fixed value '1303' as [#code1] which is good). That is biggest advantage of [#code2]
[#code1] on the other side is showing only values from node '1303' which is not good and it is always shown on every page that uses Template 'Textpage'. For example, [#code2] also shows on every article that uses Template 'Textpage' but if there is no data, it doesn't shows anything which is great. Your code [#code1] has great advantages: it splits 10 articles per page, adds numeration of pages, creates links but it is only missing one more advantage that [#code2] has, which I describe above.
I hope I exaplained it correctly, If I need to answer anything else please don't hasitate to tell me.
Thank you, Adi
Am getting a bite confused with [#code1][#code2]/!!!
Anyways looks like code1 is working as you expected so this is one thing. Now you want to do the same thing with code 2 right? If so then it will be something like
Hello Fuji,
I have also becomed confused with codes at the end;) but I had no way to describe the issue, this way via forum. I have link of my website which I would like to send you so you could see it live and difference between [#code1] and [#code2] because I simply have no way to explain it via forum. Please send me your e-mail or perhaps if I could send you pm via twitter or something like that.
Thanks in advance.
All the best, Adi
Sure here is my twitter acc https://twitter.com/twit_fuji
Hi Fuji,
this is my twitter acc @mcmdesign_de Can you please follow me so I could send you direct message? I am following your acc already.
All the best, Adi
Thanks one more time Fuji!
All the best, Adi
Hi,
I am trying to mark this topic as solved and I don't know hot to do it;( Any suggestions?
Thank you, Adi
Hi Adi. There should be a green tick at the top of each comment. Click on the one that you think best answers your question.
Thank you;)
BR, Adi
is working on a reply...