Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#21 2020-09-22 09:06:53

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: Categories list here, related article output over there

Destry, have you tried adding section="glossary" attribute to <txp:article_custom />? The latter does not inherit section from the context, unlike <txp:article />.

Offline

#22 2020-09-22 09:13:11

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,473
Website

Re: Categories list here, related article output over there

To clarify, again…

I don’t really want a category list to appear on the glossary section; it either shows a filtered list of category articles passed from the homepage, or it shows a full glossary list by default, or is shows a single full article when an article title is clicked from either the category list or the full list.

I don’t know how to say it more plainly that that. Hopeful you see what I mean.

Now, if that is not possible — say I must have a category list on the glossary too as part of the default state — I can probably live with that. But the first condition, where only a filtered list passed from the homepage appears when arriving that way, is essential.

Offline

#23 2020-09-22 09:27:37

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,946
Website

Re: Categories list here, related article output over there

If you’ve already split your page templates, then this bit goes in the page template for the homepage/default section:

<h2>Glossary categories</h2>
<txp:category_list parent="groups" exclude="groups"  wraptag="ul" break="li" class="">
    <a href="<txp:site_url />glossary/?c=<txp:category />"><txp:category title /></a>
</txp:category_list>

For want of a better way I’ve hardcoded in glossary to the url, so your category links go to the glossary section.

And this bit in the page template for the ‘glossary’ section:

<txp:if_article_list>
    <txp:if_category>
        <h2>Entries under <txp:category title /></h2>
    <txp:else />
        <h2>Full glossary<h2>
    </txp:if_category>
</txp:if_article_list>
<txp:article listform="terms_alphabetical" form="term_entry"
             wraptag="ol" break="li" class="termslist"
             sort="Title"                 
             />

I’m not sure what your article_custom bit does, but if you’re leveraging the power of txp:article, then you shouldn’t need it. The principle is:

  • txp:article with listform outputs a list. If some filtering criteria is active in the url – e.g. category, author, time etc. – the list is filtered automagically.
  • txp:article with form does the individual article bit.

The if_article_list bit in the code is only to alternate the title if you’re on a category filtering page.

Aside: the listform error with article_custom is because article_custom doesn’t have that attribute :-) It’s not context-sensitive so has only one form attribute. If you use article_custom as a container tag, you don’t need to do form="" either, as it simply uses the container.


TXP Builders – finely-crafted code, design and txp

Offline

#24 2020-09-22 09:35:01

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: Categories list here, related article output over there

Destry wrote #325995:

So in both conditions, I’m getting the same categories list and no articles.

Probably a typo: <txp:if_section section="default"> should be <txp:if_section name="default">.

Offline

#25 2020-09-22 09:35:49

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,946
Website

Re: Categories list here, related article output over there

etc wrote #326001:

Probably a typo: <txp:if_section section="default"> should be <txp:if_section name="default">.

Sorry, my bad! If you split the code into two templates as above, this bit of code is irrelevant… (I updated the earlier post and noted the edit).


TXP Builders – finely-crafted code, design and txp

Offline

#26 2020-09-22 12:46:28

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,473
Website

Re: Categories list here, related article output over there

I think we’re almost there.

This is pretty slick… and abstract. If I ever knew that before, I certainly would not have fingered it now. I peaked with Textpattern in 2010.

. . .
<txp:if_category>
  <txp:hide>
     Filtered list of articles by category magically appears here.
  </txp:hide>
<txp:else />
  <txp:hide>
     Full list of glossary articles magically appears here.
  </txp:hide>
</txp:if_category>
. . .
jakob wrote #326000:

The principle is:

  • txp:article with listform outputs a list. If some filtering criteria is active in the url – e.g. category, author, time etc. – the list is filtered automagically.
  • txp:article with form does the individual article bit.

I will try not to forget it all in three days. I’m leaving those comments in the code. ;)

The if_article_list bit in the code is only to alternate the title if you’re on a category filtering page.

What does alternate the title mean?

In any case, that all works as prescribed — thanks big time Julian — but there’s one wrench in the conceptual cog yet…

If you recall, the full glossary list is supposed to be output in alphabetical sections, I mentioned that in a previous code example. Here it is again…

<section id="a" class="terms">
    <h2>A</h2>
    <txp:article_custom category="a" 
                        sort="Title"
                        wraptag="ol" 
                        class="termslist" 
                        break="li" 
                        form="terms_alphabetical" />
  </section>
  <txp:hide>Blocks B through Z not shown here</txp:hide>

The only reason I used article_custom, not because I knew what I was doing, but because I thought if you needed more than one list of articles to output, then you needed to use article_custom each time.

Do you see the pattern? When the ‘Glossary’ link in main nav is clicked, they should get the full glossary set of articles, but the articles will be presented in <section>s by alphabetical letter:

  • A
  • B
  • C
  • etc.

Last edited by Destry (2020-09-22 13:20:05)

Offline

#27 2020-09-22 12:56:37

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,473
Website

Re: Categories list here, related article output over there

I will try it using just article tags and see if it grabs.

Offline

#28 2020-09-22 13:00:56

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,946
Website

Re: Categories list here, related article output over there

I think you excerpted a bit too much in your code block there (if_article_list doesn’t have those attributes and if_category is not responsible for filtering)?

The principle is txp:article does the automagic filtering according the context specified in the url, e.g. /glossary/?c=category-name (or /glossary/?author=destry etc.). If there’s no context it outputs the entire list (afterthought: you need to add a high limit="9999" attribute if you want a lot on one page).

Destry wrote #326013:

What does alternate the title mean?

All the txp:if_category tag does in my example above is do:

  • if this is a category page, show me the “Entries under {category title here}” heading with the current category title inserted … else …
  • if this isn’t a category page, show me the “Full glossary” heading.

I peaked with Textpattern in 2010.

I don’t think so, seeing as you wrote the long-time-definitive article on txp building blocks :-)


TXP Builders – finely-crafted code, design and txp

Offline

#29 2020-09-22 13:09:02

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,946
Website

Re: Categories list here, related article output over there

Destry wrote #326013:

If you recall, the full glossary list is supposed to be output in alphabetical sections, I mentioned that in a previous code example. Here it is again…

<section id="a" class="terms">...

The only reason I used article_custom, not because I knew what I was doing, but because I thought if you needed more than one list of articles to output, then you needed to use article_custom each time.

I knew there must be something to complicate the matter ;-)

You’re right, if you use txp:article_custom, you’ll need to include section="glossary" as Oleg said and if you’re on a category page, you’ll need category='<txp:category />' too (with single quotes for tag-in-tag output).

I think there was a newer matching method that Oleg pointed out once before. Oleg was that just with category (just the word) as an attribute, or with match="…". I’ve forgotten.

I vaguely remember now that there was an old post on that somewhere. I’m wondering whether you might be able to get around the whole 26 sets of article_custom tags by using txp:if_different in the listform you specify for txp:article, i.e. have the initial letter appear as interim headings. I must have a think about that.


TXP Builders – finely-crafted code, design and txp

Offline

#30 2020-09-22 13:12:25

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,473
Website

Re: Categories list here, related article output over there

jakob wrote #326017:

I think you excerpted a bit too much in your code block there…

Gah. Quite right. (FIXED). But it’s not that way in my page. Forum editing is tiring. More effort has gone into just trying to communicate the idea than anything else. :{

So, getting back to my ‘alphabetical set of lists’ issue, if I do this…

. . .
<txp:else />
<section id="a" class="terms">
  <h2>A</h2>
  <txp:article_custom category="a" 
       sort="Title"
       wraptag="ol" 
       class="termslist" 
       break="li" 
       form="terms_alphabetical" />
</section>
<section id="a" class="terms">
  <h2>B</h2>
  <txp:article_custom category="b" 
       sort="Title"
       wraptag="ol" 
       class="termslist" 
       break="li" 
       form="terms_alphabetical" />
</section>
. . . etc . . .

Instead of just leave it with the default empty nothing…

<txp:hide>Full list of glossary articles magically appear here.</txp:hide>

Then the output is the full glossary twice:

  1. once with the alphabetical section lists as desired
  2. once with the the full glossary list without sections

I can see how that is happening now, but I only want the first situation.

Last edited by Destry (2020-09-22 13:20:53)

Offline

Board footer

Powered by FluxBB