Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2020-09-21 15:02:26

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,752
Website

Re: Categories list here, related article output over there

Destry wrote #325979:

If my nav is: Homepage, Glossary

And I’m attempting to try and achieve both of these conditions:

Condition A:

Homepage has list of categories that send a person to the Glossary section when a given category is clicked, and displays the filtered list of glossary articles for that category, and will display only the full article when a given article in the filtered list is clicked.

Condition B:

Glossary landing view, by default (i.e. if clicking the Glossary link in main nav) will show the full glossary (i.e. full set of glossary articles regardless of categories), and will display only a full article when a given article is clicked.

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

  • Use txp:article’s automatic context awareness for the glossary section using listform="glossary_listing" for the items in the list of entries and form="glossary_fullentry" for the individual glossary pages with the descriptions. If your address bar URL has a /glossary/?c=category-name that will automatically filter the list by category.
  • For the homepage, just output the category_list of the categories, e.g. all children of groups excluding groups and fashion links to href="<txp:site_url />glossary/?c=<txp:category />" so that when a category title is clicked on, it takes you to the filtered glossary list.

Something like:

<h1>Glossary</h1>
<txp:if_section name="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>
        </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>

I’ve forgotten, but there may be a better URL structure for section/category-name/ now since 4.8. I’m sure someone can chime in there.

If you very much want to filter via the homepage and not the glossary subsection, you can filter by articles directly on the homepage section if you:

  • in the section settings for the glossary section, allow that section to show on homepage, and
  • on the sections that shouldn’t display on the homepage (e.g. about, contact etc.), set them not to show on the homepage. You can still show them in a sidebar etc. if you want by explicitly calling them via an article_custom tag.

EDIT: corrected if_section section="…" attribute to txp:if_section name="…". Thanks for spotting that Oleg.


TXP Builders – finely-crafted code, design and txp

Offline

#14 2020-09-21 17:58:04

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,096
Website GitHub Mastodon Twitter

Re: Categories list here, related article output over there

jakob wrote #325982:

I’ve forgotten, but there may be a better URL structure for section/category-name/ now since 4.8. I’m sure someone can chime in there.

Enclose the tags in <txp:article_custom section="glossary" form="" listform=""> as mentioned above. Your code seems lovely by the way:)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#15 2020-09-21 19:34:20

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,752
Website

Re: Categories list here, related article output over there

colak wrote #325985:

Enclose the tags in <txp:article_custom section="glossary" form="" listform=""> as mentioned above. Your code seems lovely by the way:)

Hi Yiannis. I saw what you wrote before but I didn’t understand it 😳. I had read it as iterating over 10 articles in the glossary section ignoring forms but including the category_list each time? But maybe it’s a new trick I’ve not grocked yet.

But even reading over my own post, it looks too simple: I’m sure Destry’s case is more complex and there’s a reason he hasn’t gone for that option already. We’ll have to see what he says :-)


TXP Builders – finely-crafted code, design and txp

Offline

#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: 4,752
Website

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,255
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: 4,752
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: 5,255
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

Board footer

Powered by FluxBB