Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2010-07-30 04:46:26
- deanacus
- New Member
- Registered: 2010-07-30
- Posts: 3
If_different conundrum
Hi all,
As a preface to this, I have looked back through 30 pages of the “How Do I… ?” forum, as well as using the search function on both the forums and the weblog/textbook, all to no avail unfortunately. That said, if there is another thread that answers this question, then please point me in the right direction
So, what I’m trying to do is set up a list of articles in the “blog” section of my site, sorted by year, and month, with each month being contained within a “<section>” within each years “<article>” (yep, building my site with the new elements in HTML5). This weblog article gave me what I though would be a good start, but unfortunately, I can;t work out how to nest the if_different tags or ensure that when a new year starts, the old year is closed.
I hope i’m making sense. if not, here is an illustration of what I’m trying to achieve:
<section id="archive"> <article class="year"> <h2>2010</h2> <section class="month"> <h3>July</h3> <ol> <li> <a href="#">POST TITLE</a> </li> <li> <a href="#">POST TITLE</a> </li> </ol> </section> <section class="month"> <h3>March</h3> <ol> <li> <a href="#">POST TITLE</a> </li> </ol> </section> </article> <article class="year"> <h2>2009</h2> <section class="month"> <h3>December</h3> <ol> <li> <a href="#">POST TITLE</a> </li> </ol> </section> </article>
I’m just hoping that someone might be able to point out a way to achieve this. The code I’ve been working with is this:
<article class="year"><!-- Start With A Year--> <h2><txp:posted format="%Y" /></h2> <txp:if_different> </ol> </section> </article><!--close the previous year--> <article class="year"><!-- Start The New Year--> <h2><txp:posted format="%Y" /></h2> </txp:if_different> <section class="month"><!-- Start with a month --> <h3><txp:posted format="%B" /></h3> <ol> <txp:if_different> </ol> </section><!-- End the month --> <section class="month"><!-- Start the month --> <h3><txp:posted format="%B" /></h3> <ol> </txp:if_different> <li><txp:posted format="%d" />: <txp:permlink><txp:title /></txp:permlink></li>
but it’s just all kinds of wrong, and in the end I’ve hurt my brain to the point where it refuses to try to comprehend how to do this without asking for help.
Any help would be greatly appreciated.
Edit: for the none pre-formatted first code block
Last edited by deanacus (2010-07-30 04:48:23)
Offline
Re: If_different conundrum
Hi danacus,
check this thread to see if the “advanced” usage of if_different there gives you a clue. (I must confess I can’t recall what I did there, I should go thru my own code and its explanation once again).
Offline
#3 2010-07-30 05:21:57
- deanacus
- New Member
- Registered: 2010-07-30
- Posts: 3
Re: If_different conundrum
Thanks for that Maniqui.
I’m not going to lie. 99% of it is going over my head. I’m not sure its because I genuinely don’t get it, or just because my brain has gone to sleep.
Either way, I’ll have a play and see what I can come up with.
For the last few minutes though, I’ve been playing with something that is far far far simpler than my jumbled mess from before, but involved three nested forms.
Basically I’m doing is calling the first form “deanacus_blog_archive_year” from the page template, which in turn calls “deanacus_blog_archive_month”, and then “deanacus_blog_archive_output” like so:
<txp:article form="deanacus_blog_archive_year" pgonly="0" searchall="0" />
deanacus_blog_archive_year:
<txp:if_different> <article class="year"> <h2><txp:posted format="%Y" /></h2> <txp:output_form form="deanacus_blog_archive_month" /> </article> </txp:if_different>
deanacus_blog_archive_month:
<txp:if_different> <section class="month"> <h3 class="month"><txp:posted format="%B" /></h3> <ol> <txp:output_form form="deanacus_blog_archive_output" /> </ol> </section> </txp:if_different>
and finally, deanacus_blog_archive_output:
<li> <txp:permlink><txp:title /></txp:permlink> </li>
That has almost gotten me to where I want to be, except it is unfortunately listing the year for each article within the same year, like this:
<article class="year"> <h2>2010</h2> <section class="month"> <h3 class="month">July</h3> <ol> <li><a="#">Post Title</a></li> </ol> </section> </article> <article class="year"> <h2>2010</h2> <section class="month"> <h3 class="month">June</h3> <ol> <li><a href="#">Post Title</a></li> </ol> </section> </article> <article class="year"> <h2>2009</h2> <section class="month"> <h3 class="month">June</h3> <ol> <li><a href="#">Post Title</a></li> </ol> </section> </article>
Offline
#4 2010-07-31 05:26:44
- deanacus
- New Member
- Registered: 2010-07-30
- Posts: 3
Re: If_different conundrum
Well, after playing around for ages, I ended up giving up on containing the year in an “article” and each month in a “section” within the article. I’m just using headings for the month and year, and trying to stick each month’s articles in an ordered list underneath the month heading. I’ve resorted to basically using the exact code from the weblog entry I linked to in my first post, just bastardising it a little bit.
Basically, I’m trying to use a variable (listopen) to that is used when the if_different evals to true to close the list. I’ve done this to eliminate the need for closing ol tags before I’ve even opened them. I hope that makes sense. Unfortunately, something is still not right, and I don’t quite understand what’s happening, or how to fix it. My form is as below:
<txp:if_different> <txp:if_variable name="listopen" value="yes"><!--Start checking if variable is set --> </ol> </txp:if_variable><!--End checking if variable is set --> <h2 class="year_title"><txp:posted format="%Y" /></h2> </txp:if_different> <txp:if_different> <txp:if_variable name="listopen" value="yes"><!--Start checking if variable is set --> </ol> </txp:if_variable><!--End checking if variable is set --> <h3 class="month_title"><txp:posted format="%B" /></h3> <ol> <txp:variable name="listopen" value="yes" /> </txp:if_different> <li><txp:permlink><txp:title /></txp:permlink></li>
Can anybody help by explaining what I’m doing wrong here? In case it’s required, I’ve attached a tag trace below:
[Form: deanacus_blog_archive_month] <txp:if_different> [<txp:if_different>: true] <txp:if_variable name="listopen" value="yes"> [<txp:if_variable name="listopen" value="yes">: false] </txp:if_variable> <txp:posted format="%Y" /> </txp:if_different> <txp:if_different> [<txp:if_different>: true] <txp:if_variable name="listopen" value="yes"> [<txp:if_variable name="listopen" value="yes">: false] </txp:if_variable> <txp:posted format="%B" /> <txp:variable name="listopen" value="yes" /> </txp:if_different> <txp:permlink> <txp:title /> </txp:permlink> [article 4] [Form: deanacus_blog_archive_month] <txp:if_different> [<txp:if_different>: true] <txp:if_variable name="listopen" value="yes"> [<txp:if_variable name="listopen" value="yes">: true] </txp:if_variable> <txp:posted format="%Y" /> </txp:if_different> <txp:if_different> [<txp:if_different>: true] <txp:if_variable name="listopen" value="yes"> [<txp:if_variable name="listopen" value="yes">: true] </txp:if_variable> <txp:posted format="%B" /> <txp:variable name="listopen" value="yes" /> </txp:if_different> <txp:permlink> <txp:title /> </txp:permlink> [article 2] [Form: deanacus_blog_archive_month] <txp:if_different> [<txp:if_different>: true] <txp:if_variable name="listopen" value="yes"> [<txp:if_variable name="listopen" value="yes">: true] </txp:if_variable> <txp:posted format="%Y" /> [<txp:if_different>: false] </txp:if_different> <txp:if_different> [<txp:if_different>: true] <txp:if_variable name="listopen" value="yes"> [<txp:if_variable name="listopen" value="yes">: true] </txp:if_variable> <txp:posted format="%B" /> <txp:variable name="listopen" value="yes" /> </txp:if_different> <txp:permlink> <txp:title /> </txp:permlink> [article 5] [Form: deanacus_blog_archive_month] <txp:if_different> [<txp:if_different>: true] <txp:if_variable name="listopen" value="yes"> [<txp:if_variable name="listopen" value="yes">: true] </txp:if_variable> <txp:posted format="%Y" /> </txp:if_different> <txp:if_different> [<txp:if_different>: true] <txp:if_variable name="listopen" value="yes"> [<txp:if_variable name="listopen" value="yes">: true] </txp:if_variable> <txp:posted format="%B" /> <txp:variable name="listopen" value="yes" /> </txp:if_different> <txp:permlink> <txp:title /> </txp:permlink>
Offline
Pages: 1