Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Plugin search: nested section & article list
I am looking for a plugin that creates a linked unordered list with all my sectins, while nesting my articles in it.
Like so:
<ul id="menu">
<li>Section
<ul>
<li><a href="#" title="Link">Article</a></li>
<li><a href="#" title="Link">Article</a></li>
<li><a href="#" title="Link">Article</a></li>
</ul></li>
<li>Section
<ul>
<li><a href="#" title="Link"> Article </a></li>
<li><a href="#" title="Link"> Article </a></li>
</ul></li>
<li>Section
<ul>
<li><a href="#" title="Link"> Article </a></li>
</ul></li>
</ul>
Offline
#2 2008-03-05 12:46:12
- redbot
- Plugin Author
- Registered: 2006-02-14
- Posts: 1,410
Re: Plugin search: nested section & article list
You can obtain it without a plugin.
in your page form put
<ul><txp:article_custom form="my_form" sort="section" /></ul>
and in your article form (my_form)
<li>
<txp:if_different>
<txp:section />
</txp:if_different>
<a href="#" title="Link"> Article </a>
</li>
Last edited by redbot (2008-03-05 12:46:36)
Offline
Re: Plugin search: nested section & article list
Thanks for the reply redbot. This works, but I actually need it to nest another ul inside the first. Your technique only creates clear text. Any ideas?
Offline
#4 2008-03-05 16:22:54
- redbot
- Plugin Author
- Registered: 2006-02-14
- Posts: 1,410
Re: Plugin search: nested section & article list
Well it’s way more tricky then. Firstly I suggest you to read well this topic. Then you can try this, though I’ve not tested it (and because of the way nested conditionals are handled you must use yet another form).
in your page form put
<ul><txp:article_custom form="my_form" sort="section" /></ul>
in your article form (my_form)
<txp:if_different>
<txp:output_form form="first_article" />
<txp:section /><ul>
</txp:if_different>
<li><a href="#" title="Link"> Article </a></li>
<txp:if_last_article>
</ul>
</txp:if_last_article>
then create another form (i.e. first_article) like so:
<txp:if_first_article>
<txp: else />
</ul>
</txp:if_first_article>
I hope it works, otherwise I think you’ll have to use directly php (see ruud’ example in the topic linked before)
Offline
Re: Plugin search: nested section & article list
redbot’s example misses li
s. Like:
<ul><txp:article_custom form="my-form" sort="section asc" /></ul>
Form named my-form:
<txp:if_different>
<txp:output_form form="first-article" />
<li>
<txp:section title="1" />
<ul>
</txp:if_different>
<li><txp:permlink><txp:title /></txp:permlink></li>
form named first-article:
<txp:if_first_article><txp: else /></ul></li></txp:if_first_article>
Offline
Re: Plugin search: nested section & article list
Thanks a lot. This works.
The only modification which I needed was
<ul id="menu"><txp:article_custom form="menu" sort="section asc" /></ul></ul>
(Two closing </ul>. I am not entirely sure why, but it was needed.)
The last question that I have is how can I sort the sections manually?
Offline
Re: Plugin search: nested section & article list
Actually it is not entirely working. In two out of the three sections the article list works nicely. For the third section an additional first class li is created. (Look at http://www.artistico.de/1_was/test-headinfg to see what I mean.)
Last edited by dl33 (2008-03-05 20:00:16)
Offline
#8 2008-03-05 19:51:39
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Plugin search: nested section & article list
dl33 wrote:
The last question that I have is how can I sort the sections manually?
Using if_different means that you can only sort your sections alphabetically, either ascending or descending. But you can change the section names to achieve the sort order you want: 01-section3, 02-section1, 03-section2, etcetera.
Offline
Re: Plugin search: nested section & article list
About what I mentioned earlier: The section that is split into two or more <li>s is always first. (http://www.artistico.de/1_was/test-headinfg)
At the moment I am using Gocom’s code with the exception of the extra <ul>.
Offline
#10 2008-03-05 22:25:14
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Plugin search: nested section & article list
You’re missing a </li>
before the last </ul>
. Add this to Gocom’s code, at the bottom of form ‘my-form’:
<txp:if_last_article></ul></li></txp:if_last_article>
and delete one of the two </ul>
s after the article_custom tag.
Offline
Re: Plugin search: nested section & article list
I now have this:
<ul><txp:article_custom form="menu" sort="section asc" /></ul>
form “menu”
<txp:if_different>
<txp:output_form form="menu_li" />
<li>
<txp:section title="1" />
<ul>
</txp:if_different>
<li><txp:permlink><txp:title /></txp:permlink></li>
<txp:if_last_article></ul></li></txp:if_last_article>
form menu_li
<txp:if_first_article><txp: else /></ul></li></txp:if_first_article>
The extra ul is not needed now, but the first section is still split… even though the code is 100% valid, which means that the loop runs correctly, it just thinks that the first section is two sections…
Last edited by dl33 (2008-03-05 22:47:29)
Offline
#12 2008-03-05 22:48:41
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Plugin search: nested section & article list
Ah, now I see what you mean. I suspect that has to do with the fact that there is more than one txp tag inside the if_different tags. Can you take out the <txp:output_form form="menu_li" />
and look if that helps? I know that it will cause missing list tags, but it’s just to see if it solves the double section output.
Offline