Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-01-05 11:13:39

Manaus
Member
From: Turin, Italy
Registered: 2010-10-22
Posts: 252
Website

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

#2 2011-01-05 11:48:12

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Link to year/month group in blog

Not an exact match to your request, but you might find the info you need here:

http://txptips.com/archive-page-with-some-style


Code is topiary

Offline

#3 2011-01-06 17:32:09

Manaus
Member
From: Turin, Italy
Registered: 2010-10-22
Posts: 252
Website

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

#4 2011-01-06 18:08:59

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

Board footer

Powered by FluxBB