Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2010-01-24 10:01:09
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
pagination and menu problem [solved]
Hello,
I have some categories(months) which contains several articles.
Now I want to display on page 1 of a category (month) 2 articles and on the rest 3 articles.
On another category (month) I want on the first page 1 articles and on the rest 2 articles.
I’m now using the smd-if plugin to achieve this ?
But is there a better way ?
Roelof
Last edited by roelof (2010-02-03 19:30:26)
Offline
Re: pagination and menu problem [solved]
You could probably go completely plugin free for this, with a combination of if_category, this tip for targeting page 1, plus appropriate use of limit
and offset
attributes in your article
tags.
Code is topiary
Offline
#3 2010-01-24 18:20:05
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: pagination and menu problem [solved]
Oke,
I will try your suggestion.
On the old site I have this :
http://pastebin.com/mc0b000c
And as you can see it becoming a big spaghetti.
Roelof
Last edited by roelof (2010-01-24 18:27:06)
Offline
#4 2010-01-28 13:48:07
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: pagination and menu problem [solved]
Oke,
And it there a solution if i don’t want to make all months are category ?
Roelof
Offline
#5 2010-01-28 19:17:23
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: pagination and menu problem [solved]
roelof wrote:
And as you can see it becoming a big spaghetti.
Oh dear, can you still make sense of all that code? Wow. And it will only grow when your site grows… ;)
And it there a solution if i don’t want to make all months are category ?
If I’m not mistaken your months are not categories now, right? I wouldn’t recommend making them categories, you’ll still need the same amount of conditionals, and you’ll need to create all those categories. So, only more work…
Listen, how many different situations are there? 2 articles on the first page, 3 on the following pages; 1 article on the first and 2 on the following pages; that’s just two. How many do you think you’ll need alltogether?
Offline
#6 2010-01-28 19:35:53
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: pagination and menu problem [solved]
Hello Els,
I can’t make anymore sense of that soup.
Therefore I asked help from the pro’s.
As far as I can see there are 5 situations.
1) 2 on the frontpage.
2) 1 on the page ( articles – 2005-09 page 8
– 2006-07 page 1
– 2008-05 , page 1
3) 3 on a page
4) 2 on the other pages
5) 5 on a page
6) as many articles as there are on a page.
Roelof
Offline
#7 2010-01-28 20:54:33
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: pagination and menu problem [solved]
Roelof, I’m thinking of a completely different way to handle the pagination, because my guess is that you want to decide how many articles a page has depending on the length of the articles, and the way you are doing it now you can go on forever expanding your code.
What I have in mind is using a custom field to enter the page number, your code on the page can then be very short, but you’ll have to fill those custom fields for all articles first. I think it can be done this way because your articles are sorted from older to newer, the other way around would be much harder.
Do you think that’s workable for you, figuring out a page number for each article and putting it in a custom field? If so, I think I can work out a code example for you.
Offline
#8 2010-01-28 21:10:36
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: pagination and menu problem [solved]
Hello Els.
That can be workable for me because I can see on the old site which page a article has.
Im working on a new site because the site needs a new menu. i’m now trying to make a multi-collumm work for the site.
Roelof
Offline
#9 2010-01-28 21:33:54
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: pagination and menu problem [solved]
Edit: I changed the code below because this doesn’t work with <txp:article />
(limit and offset problems). It does work however with article_custom, and though the regular pagination and pagination plugins won’t work, you can even create a simple pagination using that same article_custom tag.
---
roelof wrote:
That can be workable for me because I can see on the old site which page a article has.
Yes, that’s easy, but remember you’ll also have to enter a page number for each new article. Well, that won’t be a big problem either I guess, you can always change it if it turns up on the wrong page.
i’m now trying to make a multi-collumm work for the site.
Hmm… I think I figured out a way to handle your pagination, but I’m not so sure it will be easy to adapt for multi column article display…
Anyway, here’s my idea (for a one column site) (and not tested even tested, sort of)
Create a custom field named “pagenr” (or whatever you like). Use it to enter the page number the article should be displayed on ;) On your page use this code:
<txp:if_section name="default">
<txp:variable name="monthpage" value='<txp:page_url type="month" />' />
<txp:variable name="pagenumber" value='<txp:page_url type="pg" />' />
<!-- check if we're on a monthly archive page or not -->
<txp:if_variable name="monthpage" value="">
<!-- no, this is the frontpage -->
<txp:article_custom section="voorpagina" form="default" />
<txp:else />
<txp:article_custom month='<txp:page_url type="month" />' section="yoursection" pagenr='<txp:if_variable name="pagenumber" value="">1<txp:else /><txp:page_url type="pg" /></txp:if_variable>' limit="99" form="dagboek" sort="Posted asc" />
<!-- pagination -->
<ul><txp:article_custom month='<txp:page_url type="month" />' section="yoursection" sort="custom_1 asc, posted asc" limit="99">
<txp:if_different><li><a href="?month=<txp:page_url type="month" />&pg=<txp:custom_field name="pagenr" />"><txp:custom_field name="pagenr" /></a> </li></txp:if_different>
</txp:article_custom></ul>
</txp:if_variable>
</txp:if_section>
(The variable name="pagenumber"
and if_variable name="pagenumber"
part is to set the page number to “1” if we are on the first page, and no page number is in the URL.)
The attribute pagenr
in the article tag should be the exact name of your custom field!
I’m very curious myself if this really works… ;) It’s basic, but it definitely works.
Roelof, even if you are never going to use this code, I’ve had a lot of fun figuring it out :)
Last edited by els (2010-01-28 23:17:42)
Offline
#10 2010-01-29 09:26:21
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: pagination and menu problem [solved]
Hello Els,
thank you and I will use it for sure.
It’s better then tht spaghetti-code.
I have one more question.
The new code for the menu looks like this :
<div id="navigation">
<ul id="topnav">
<li><a href="#" class="home">Home</a></li>
<li>
<a href="#" class="products">Products</a>
<div class="sub">
<ul>
<li><h2><a href="#">Desktop</a></h2></li>
<li><a href="#">Navigation Link</a></li>
<li><a href="#">Navigation Link</a></li>
</ul>
<ul>
<li><h2><a href="#">Laptop</a></h2></li>
<li><a href="#">Navigation Link</a></li>
<li><a href="#">Navigation Link</a></li>
</ul>
<ul>
<li><h2><a href="#">Accessories</a></h2></li>
<li><a href="#">Navigation Link</a></li>
<li><a href="#">Navigation Link</a></li>
</ul>
<ul>
<li><h2><a href="#">Accessories</a></h2></li>
<li><a href="#">Navigation Link</a></li>
<li><a href="#">Navigation Link</a></li>
</ul>
</div>
</li>
<li><a href="#" class="sale">Sale</a></li>
<li><a href="#" class="community">Community</a></li>
<li><a href="#" class="store">Store Locator</a></li>
</ul>
</div>
I can adapt this code.
<ul class="select">
<li class="line">
<a href="#nogo"><b><txp:variable name="menu3" /> </b>
<!--[if IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<txp:article_custom category='<txp:variable name="menu2" />' wraptag="ul" break="" class="sub" sortdir="asc" limit="999">
<txp:if_different>
<li class="subline">
<a href="<txp:site_url />?c=<txp:variable name="menu2" />&month=<txp:posted format="%Y-%m" />"><txp:posted format="%b" /></a>
</li>
</txp:if_different>
</txp:article_custom>
</txp:category_list>
but as you can see at the older site I get a lot a white between the html code.
Is there also a better solution.
Roelof
(added blank line before first bc..
-Els)
Last edited by els (2010-01-29 18:11:22)
Offline
#11 2010-01-29 11:38:43
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: pagination and menu problem [solved]
Hello Els,
I tried it myself and made this script.
<div id="navigation">
<ul id="topnav>
<li>
<txp:article_custom category='<txp:variable name="menu2" />' wraptag="li" break="" class="sub" sortdir="asc" limit="999">
<div class="sub">
<ul>
<li><h2><a href="#">Category2</a></h2></li>
<li>
<txp:if_different>
<a href="<txp:site_url />?c=Category2&month=<txp:posted format="%Y-%m" />"><txp:posted format="%b" /></a>
</li>
</txp:if_different>
</txp:article_custom>
</ul>
</txp:category_list>
Do you think this can work.
Roelof
(added blank line before bc..
. -Els)
Last edited by els (2010-01-29 18:13:25)
Offline
#12 2010-01-29 18:14:32
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: pagination and menu problem [solved]
Hi Roelof, I don’t have time today, but I’ll have a look at it tomorrow. Or maybe someone else can help you in the meantime ;)
Edit: maybe you’d better add something like “and menu” to the topic subject; you can do that by editing your first post.
Last edited by els (2010-01-29 18:15:45)
Offline