Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Using variables to determine specific url
I have an archive page that outputs a list of the current month’s articles as standard (/archives) but I also use upm_date_archive to output a ‘month menu’ e.g. January (12), and the corresponding lists when a particular ‘month menu’ item has been clicked. Due to the nature of the upm_date_archive plugin, which does not allow me to display a ‘current month’ list from the /archives url, I have had to resort to using variables to show particular content; if I did not, I would have both the current month list and the individual month list displayed on top of one another.
My code so far is:
<txp:variable name="archive" value='<txp:site_url />archives/' />
<txp:if_variable name="archive" value='<txp:site_url />archives/'>
<txp:article_custom limit="999" wraptag="ul" break="" month='<txp:php>echo date("Y-m");</txp:php>' sort="Posted desc">
<txp:if_different>
<li class="month"><h4><txp:posted format="%B" /> <txp:posted format="%Y" /></h4></li>
</txp:if_different>
<li>
<p class="title"><txp:permlink><txp:title /></txp:permlink></p>
</li>
</txp:article_custom>
<txp:else />
<txp:upm_date_archive form="archive_view" mode="smart" heading_level="4" include_date="no" sort="the_year desc, the_month desc, the_date desc" />
</txp:if_variable>
If you’re confused as I am, here’s a breakdown of what I want displayed on what urls:
<txp:site_url />archives/
– Current month list with permalinked titles to articles
<txp:site_url />archives/2010-02
or
<txp:site_url />archives/2010-01
etc – Specific month list from that particular url (the upm_date_archive plugin handles this)
Any pointers would be greatly appreciated.
Admin Themes Prometheus | Stung | <txp:coder/
My Portfolio | ɹǝpuɐz.com | @MrMartineau
<txp:coder /> – Convert your designs into Textpattern-based websites
jQuery Style | @jquerystyle
Offline
Re: Using variables to determine specific url
Can’t say I do quite understand exactly what you’re after, but here are two minor observations:
<txp:variable name="archive" value='<txp:site_url />archives/' />
<txp:if_variable name="archive" value='<txp:site_url />archives/'>
The if_variable
will always evaluate true.
<txp:posted format="%B" /> <txp:posted format="%Y" />
Same as <txp:posted format="%B %Y" />
Last edited by jsoo (2010-02-11 13:22:14)
Code is topiary
Offline
Re: Using variables to determine specific url
I’m not so familiar with upm_date_archive but if the link is essentially a query string (e.g. ?month=) rewritten for clean urls (e.g. still a GET value), you can use adi_gps to check for an url query for “month”. adi_gps helpfully automatically puts that in a variable so that you can use if_variable to test if the url is requesting a specific month or not.
TXP Builders – finely-crafted code, design and txp
Online
Re: Using variables to determine specific url
jsoo wrote:
The
if_variable
will always evaluate true.
Ok, I didn’t realise.
<txp:posted format="%B" /> <txp:posted format="%Y" />
Same as<txp:posted format="%B %Y" />
Thanks, I feel like a bit of a douche not thinking of that before.
Admin Themes Prometheus | Stung | <txp:coder/
My Portfolio | ɹǝpuɐz.com | @MrMartineau
<txp:coder /> – Convert your designs into Textpattern-based websites
jQuery Style | @jquerystyle
Offline
Re: Using variables to determine specific url
As jakob said, TXP has inbuild ?month=
selector for <txp:article/>
tags. If we use same kind of format for the custom listing, we get a completely pluginless solution:
<txp:variable name="month" value='<txp:php> gps("month"); </txp:php>' />
<txp:if_variable name="month" value="">
<!--
This month
-->
<txp:article_custom month='<txp:php>echo safe_strftime("%Y-%m"); </txp:php>' />
<txp:else />
<!--
Selected month
-->
<txp:article_custom month='<txp:php>echo gps("month");</txp:php>' />
</txp:if_variable>
Links in un-rewritten format are archives/?month=2009-12
etc.
Last edited by Gocom (2010-02-11 13:34:31)
Offline
Re: Using variables to determine specific url
As it happens, I have just been working on month-based article lists for a client. Probably I’d be better off using upm_date_archive
, but felt like seeing what I could do with core tags. Anyway, this might give you ideas for solving your problem.
I’m not using a special archive page, just the section front page. This is in the page template:
<txp:variable name="month" value='<txp:rah_get_date format="%B %Y" />' />
<txp:if_variable name="month" value="">
<!-- not a month-based list -->
<txp:else />
<h2>Archives: <txp:variable name="month" /></h2>
</txp:if_variable>
<txp:article />
I’m using the handy little rah_get_date
plugin so it’s not exactly plugin-free, but could have used a small bit of raw PHP instead.
So maybe you could use a similar conditional to distinguish between /archives/
and, say, /archives/?month=2009-02
.
Speaking of rah_get_date
, Gocom beat me to it.
Code is topiary
Offline
Re: Using variables to determine specific url
jsoo wrote:
I’m using the handy little
rah_get_date
plugin so it’s not exactly plugin-free, but could have used a small bit of raw PHP instead.
Yes. It is indeed really small plugins with minimal lines of code. Nothing special so to speak :-)
Speaking of
rah_get_date
, Gocom beat me to it.
I’m 6 feet tall and violent. lol.
Last edited by Gocom (2010-02-11 13:40:39)
Offline
Re: Using variables to determine specific url
The upm_date_archive plugin does not use /?month=2009-02
urls it uses /2010-02
for example. This means that I cannot use the month
in the url, any ideas?
Admin Themes Prometheus | Stung | <txp:coder/
My Portfolio | ɹǝpuɐz.com | @MrMartineau
<txp:coder /> – Convert your designs into Textpattern-based websites
jQuery Style | @jquerystyle
Offline
Re: Using variables to determine specific url
rathersplendid wrote:
The upm_date_archive plugin does not use
/?month=2009-02
urls it uses/2010-02
for example. This means that I cannot use themonth
in the url, any ideas?
I’m generating the URLs manually:
<txp:article_custom section='<txp:section />' limit="9999">
<txp:if_different>
<a href="<txp:site_url /><txp:section />/?month=<txp:posted format="%Y-%m" />"><txp:posted format="%B %Y" /></a><br />
</txp:if_different>
</txp:article_custom>
Keeping in mind that a no-limit article_custom
isn’t a terribly efficient way to query the database …
Code is topiary
Offline
Re: Using variables to determine specific url
I have actually managed to fix my problem with a surprisingly simple solution, instead of linking to /archives
, from the menu, I have linked to /archives/<txp:php>echo date("Y-m");</txp:php>
which link to the current year-month as I needed.
Thanks for all your help though, I can’t believe I didn’t think of it sooner, and this forum is brilliant!
Admin Themes Prometheus | Stung | <txp:coder/
My Portfolio | ɹǝpuɐz.com | @MrMartineau
<txp:coder /> – Convert your designs into Textpattern-based websites
jQuery Style | @jquerystyle
Offline