Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
show articles by year and control how many are displayed
i’m trying to show the first…
- 9 articles from 2008 (+ at the end link to full archive of the year)
- 3 articles from 2007 (+ at the end link to full archive of the year)
- 3 articles from 2006 (+ at the end link to full archive of the year)
and so on… currently i’m using something like
<txp:if_different><h3>Year <txp:posted format="%Y" /></h3></txp:if_different> <txp:upm_article_image type="thumbnail" /> <txp:if_different> <a href="/mysection/category/<txp:posted format="%Y" />">View all articles from <txp:posted format="%Y" /></a> </txp:if_different>
but obviously that doesn’t work. is this even possible at all?!
EDIT: i’ve solved this myself, can a mod close/delete the thread?
Last edited by sthmtc (2008-02-10 11:45:42)
Offline
#2 2008-02-11 11:54:42
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: show articles by year and control how many are displayed
Want to share how you solved it?
Offline
Re: show articles by year and control how many are displayed
Mary wrote:
Want to share how you solved it?
sure, but it’s rather sketchy and involves some hardcoded mess. i’m not sure if it will be of much help to anyone… :)
basically the problem i was having was how to provide an overview of the first n articles in a given category at /section/cat grouped by year. also that list had to be expandable to display all articles in that category. i solved it by setting up an url var. like so:
<txp:chs_urlvar_default var="year"> <txp:chh_if_data> <ul><txp:chh_article month="2008" limit="9" /></ul> <p><a href="/section/cat/?year=2008">View all articles from 2008</a></p> </txp:chh_if_data>
<txp:chh_if_data>
<ul><txp:chh_article month=“2007” limit=“3” /></ul>
<p><a href=”/section/cat/?year=2007”>View all articles from 2007</a></p>
</txp:chh_if_data>
<!— and so on… —>
</txp:chs_urlvar_default>
note the difference in the limit attribute, that’s what i needed. so this gives me the article overview at /section/cat
then, if one clicks on “view all articles” it takes him to the list where all articles from that year are shown:
<txp:chs_urlvar_exists var="year"> <h3>All articles from <txp:chs_urlvar_echo var="year" /></h3> <ul><txp:asy_wondertag><txp:chh_article month="<txp:chs_urlvar_echo var="year" />" limit="9999" /></txp:asy_wondertag></ul> </txp:chs_urlvar_exists>
so if we’re at /section/cat/?year=XXXX the above snippet is used to display all articles from that year.
again, i would have loved to come up with something smarter than that and not involving that hardcoded list (i’m sure that list could be created differently) but this worked for me…
Last edited by sthmtc (2008-02-11 12:19:15)
Offline
#4 2008-02-11 17:07:26
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: show articles by year and control how many are displayed
sthmtc wrote:
i would have loved to come up with something smarter than that
I think it is rather smart :) And in my experience a certain amount of hardcoding is inevitable when a site is not a straightforward blog.
Offline