Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Link to year/month group in blog
Hello,
I have a blog structure with menu and content. In the menu section I’d like to make a month-year structure, but I don’t know how to write the link tags…. any hint?
thanks!
Offline
Re: Link to year/month group in blog
Not an exact match to your request, but you might find the info you need here:
Code is topiary
Offline
Re: Link to year/month group in blog
Thanks!
Refining the page, I need to make links to search queries. That is, I’d like to make hyperlinks with search keys that work. Currently I’ve put this code in the menu article:
<txp:if_different>
<a href="<txp:site_url />news/?q=<txp:posted format="%B %Y" />"><txp:posted format="%B %Y" /></a>
</txp:if_different>
Still, TXP doesnt recognize %B and %Y as valid search values (returns no results).
How can I fix this?
Thanks again
Offline
Re: Link to year/month group in blog
It’s not very well documented (in fact, I can’t find documentation for it anywhere) but you can use Txp’s built-in date-based URLs to retrieve articles by posted date.
<txp:if_different>
<a href="<txp:site_url />news/?month=<txp:posted format="%Y-%m" />"><txp:posted format="%B %Y" /></a>
</txp:if_different>
This gives a URL such as site.org/news/?month=2009-03
. If Txp gets such a request, an <txp:article />
tag on the page template will return articles posted in that month.
Strangely, you always use “month” as the query parameter. Why they didn’t pick “date” I have no idea. I’m pretty sure the parameter value must always be in the YYYY-MM-DD
format. It doesn’t have to be the complete date; you could use ?month=2
to find anything posted after 1999, for example :) It just has to match the date string stored in `textpattern.Posted`.
Code is topiary
Offline
Pages: 1