Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2020-09-22 07:58:44

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

Re: Categories list here, related article output over there

jakob wrote #325982:

I’m not sure you can usefully display the full article itself on the homepage (your and case) and the glossary section.

Sorry, what that should have communicated was open the full article on the Glossary section, because at that point the reader is in the Glossary section:

Condition A:

  1. Arrive to homepage; see list of categories.
  2. Click a category
  3. Be taken to Glossary section; see list of articles related to category from step 2
  4. Click an article title in the filtered article list; see full article in Glossary section.

I haven’t thoroughly read through and thought about what you and Colak have shared since my last post. I’ll do that and test a few things then report back.

Last edited by Destry (2020-09-22 08:00:03)

Offline

#17 2020-09-22 08:23:32

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,181
Website GitHub

Re: Categories list here, related article output over there

Destry wrote #325990:

  1. Arrive to homepage; see list of categories.
  2. Click a category
  3. Be taken to Glossary section; see list of articles related to category from step 2
  4. Click an article title in the filtered article list; see full article in Glossary section.

Good, that’s what the code above should do :-)

And if your code is going to get increasingly complex over time, you can always simplify things for yourself by making two (or more) page templates, one for the homepage display and one for the glossary section (and another for a static “about” or “contact” page) …


TXP Builders – finely-crafted code, design and txp

Offline

#18 2020-09-22 08:30:25

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

Re: Categories list here, related article output over there

jakob wrote #325986:

Hi Yiannis. I saw what you wrote before but I didn’t understand it 😳.

Me either. An if_section on the section? A category_list nested inside an article_custom? No way I would have ever thought to do something like that. But, my grasp of Txp digresses with time (the wrong direction).

I had read it as iterating over 10 articles in the glossary section ignoring forms but including the category_list each time?

Just tested. That is exactly what happens. Though I thought Colak also meant use it on the homepage, but maybe what he meant by ‘front page’ is the default landing view of the Glossary section. I have not tried it there yet.

I also get a tag error saying listform="" is not a recognized attribute, but that’s probably because I didn’t put a form name in it. ;)

Still reviewing the other notes…

Offline

#19 2020-09-22 08:32:46

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

Re: Categories list here, related article output over there

jakob wrote #325991:

you can always simplify things for yourself by making two (or more) page templates, one for the homepage

That’s how it is already. I don’t do the one template for the entire kingdom thing. Brain can’t handle all that conditional voodoo.

Offline

#20 2020-09-22 08:57:18

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

Re: Categories list here, related article output over there

Here’s what I have at the moment… Btw, I use a 1:1 page to section structure. I should have clarified that early on. So if I say ‘homepage’ it means default section/page. If I say ‘Glossary’ it means a ‘glossary’ page assigned to a ‘glossary’ section.

Default (homepage) template:

<txp:category_list section="glossary" 
                   parent="groups" 
                   exclude="groups" 
                   wraptag="ul" 
                   break="li" 
                   class="">
<txp:category title="1" link="1" />
</txp:category_list>

If I understood Oleg correctly, that should pass a filtered article list to the Glossary section by the power of section="glossary".

Here is what’s on the Glossary template per Julian’s suggestion, though I’ve added in an example block, letter ‘A’ section, where full glossary would supposedly output…

<h1>Glossary</h1>
<txp:if_section section="default">
    <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>
<txp:else />
    <txp:if_article_list>
        <txp:if_category>
            <h2>Entries under <txp:category title /></h2>
        <txp:else />
            <h2>Full glossary<h2>
            <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:if_category>
    </txp:if_article_list>
    <txp:article listform="terms_alphabetical" form="term_entry"
                 wraptag="ol" break="li"  class="termslist"
                 sort="Title"                 
                 />
</txp:if_section>

Behaviour…

Homepage:

  • Arrive at homepage
  • A category list displays as expected.
  • If a category link is clicked; taken to Glossary section but still see the same category list, no filtered articles.

Glossary:

  • Click ‘glossary’ link in main nav from homepage
  • Default landing view is same as above, a category list, nothing else.

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

I’m also not getting any tag errors even though the behaviour is not desired. That would be a nice feature of Textpattern, actually: If a tag structure/nesting/whatever is not acceptable in Txp, it gives an error like ‘tags assemblage from opening to closing [tag name] tags is not acceptable structure’ Don’t know how that would be done, but it would take a little mystery out of the unexpected observations when they happen.

Last edited by Destry (2020-09-22 09:06:32)

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 5,661
Website GitHub

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,912
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: 5,181
Website GitHub

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: 5,661
Website GitHub

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: 5,181
Website GitHub

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,912
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,912
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: 5,181
Website GitHub

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: 5,181
Website GitHub

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,912
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