Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-07-26 10:45:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

[Solved] Listing uncategorized content

Is listing uncategorized content possible from the URL? If so, how? Struggling here…

Using the default out-of-the-box 4.8.2 theme, here’s some code I added to the default page under the if_category portion:

<txp:if_category>
    <h1 itemprop="name"><txp:text item="category" /> <txp:category title /></h1>
    <txp:file_download_list category='<txp:category />' limit="999" wraptag="ul" break="li">
       <a href="/assets?fileid=<txp:file_download_id />"><txp:file_download_name /></a> <txp:file_download_link>(download)</txp:file_download_link>
    </txp:file_download_list>
</txp:if_category>

Works fine if I specify a category name in the URL. But two things I want to do:

  1. If there’s just /category in the URL then display a category_list of available file categories.
  2. If there’s just /category/file (or even if I make up, say, a fake link to /category/file/uncategorized) then display a list of files that are not categorized.

This is so that I can show to people on the front-end files that have yet to be put in a category so they know to go and categorize them.

I can probably get this to work either by not using Txp’s built-in category management URL scheme (i.e. make my own section called /cats or something and then manually create all the links using that Page template) or via clever use of <txp:if_request>.

I’m trying to avoid the former unless I have to, because I think it’d be nice to be able to use the category system to display them. But Txp seems to like throwing 404s before I get a chance to play. Perhaps my tests need to appear really early in the page template flow?

Am I dreaming? Is this type of thing remotely possible? Am I Just not thinking far enough outside the box to do it?

Last edited by Bloke (2020-07-26 10:49:27)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2020-07-26 11:06:15

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

Re: [Solved] Listing uncategorized content

No category is set in this case, but you can try to detect it by comparing <txp:page_url type="1" /> with category:

<txp:evaluate query='<txp:page_url type="1" escape="quote"/> = "category"'>
    <txp:if_category>
        individual category
    <txp:else />
        category list
    </txp:if_category>
</txp:evaluate>

Offline

#3 2020-07-26 11:38:37

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: [Solved] Listing uncategorized content

That solves the ‘list cats’ scenario perfectly, thank you. I was trying to pattern match using <txp:if_request> and it was rejecting my advances.

So I can do this on the default page (four-point-eight theme) now if I hack out the check for the ‘if front page’ variable in the default form and it works a treat:

<txp:evaluate query='<txp:page_url type="1" escape="quote"/> = "category"'>
    <txp:if_category>
        <h1 itemprop="name"><txp:text item="category" /> <txp:category title /></h1>
        <txp:file_download_list category='<txp:category />' limit="999" wraptag="ul" break="li">
           <a href="/assets?fileid=<txp:file_download_id />"><txp:file_download_id />: <txp:file_download_name /></a> <txp:file_download_link>(download)</txp:file_download_link>
        </txp:file_download_list>
    <txp:else />
        <txp:category_list type="file" label="Categories" labeltag="h1" wraptag="ul" break="li" />
    </txp:if_category>
</txp:evaluate>

That leaves one final thing to conquer: how do I list all the uncategorized files?

I tried this:

<txp:file_download_list category="" limit="999" />

But of course that fails and lists everything because we don’t distinguish between the default category="" case in lAtts() and user-supplied “uncategorized”. I suspect this affects a lot of tags. Is there anything can be done about it? Perhaps using category => null in the lAtts() defaults and checking that rather than ‘empty’?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2020-07-26 11:49:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: [Solved] Listing uncategorized content

Alternatively, could we add an exclude attribute to <file_download_list> so we could do:

<txp:file_download_list category="list, of, cats, here" exclude limit="999" />

or

<txp:file_download_list exclude="list, of, cats, here" limit="999" />

Neither are ideal in my specific case, as they rely on listing all the categories in one form or another, but they do permit some more flexibility for those wishing to include all but a few.

Perhaps we could permit a leading empty item in the category list to allow us to include empties in the set of content:

<txp:file_download_list category=", list, of, cats" limit="999" />

That would list uncategorised files, plus the files in “list” and “of” and “cats”.

This, by extension, would permit:

<txp:file_download_list category="," limit="999" />

to return all uncategorized content only.

Could this be extended to all tags that permit category filtering?

EDIT: Wait, <txp:file_download_list category="," limit="999" /> works! Ignore me.

Last edited by Bloke (2020-07-26 11:51:15)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2020-07-26 12:00:56

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

Re: [Solved] Listing uncategorized content

Bloke wrote #324875:

Perhaps using category => null in the lAtts() defaults and checking that rather than ‘empty’?

Looks risky bwc-wise, since atm category="" means ‘no filter’ and not ‘uncategorised’…

Alternatively, could we add an exclude attribute to <file_download_list>

As you know, my not so secret plan is to internally turn all content into custom-type ‘articles’. Then it will inherit all <txp:article /> powers for free.

EDIT: Wait, <txp:file_download_list category="," limit="999" /> works! Ignore me.

Ah, great! But looks weird :-)

Offline

#6 2020-07-27 13:25:27

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 975
Website

Re: [Solved] Listing uncategorized content

You guys are so far beyond me in your thinking and understanding – so please forgive me for even speaking up. Especially since it sounds like Steph found his solution?

Perhaps a simple fix for something like this might be to have all items assigned a value at creation that equals uncategorized (and/or in the future, un-tagged), which is then replaced when a category (and/or tag) is added? Then if you know the default value (say 0cat or 0tag) you can manipulate that rather than the odd and not really user friendly category=”“.

I suppose part of the argument against – conceptually – is that it is cleaner and reduces the database when uncategorized and untagged are truly without any value. Plus I’ve no idea on the technical viability of this idea.

As I said – I hesitate to speak because I know that I don’t know. So a luddite’s thought for what it is worth. :-D

Last edited by maverick (2020-07-27 13:26:07)

Offline

#7 2020-07-27 13:36:58

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: [Solved] Listing uncategorized content

maverick wrote #324903:

have all items assigned a value at creation that equals uncategorized

That would indeed work. Just need to remember to omit that value (probably via exclude) if making category lists.

In this case though, I was more interested if it could be done rather than finding ways around it. I’m kinda glad the ‘empty placeholder’ trick works, even though it’s not obvious. At least it means stuff is accessible if it’s uncategorized.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#8 2020-07-27 14:07:53

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 975
Website

Re: [Solved] Listing uncategorized content

Bloke wrote #324906:

I’m kinda glad the ‘empty placeholder’ trick works, even though it’s not obvious. At least it means stuff is accessible if it’s uncategorized.

That is a trick worth remembering!

Offline

#9 2020-07-27 14:11:39

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 975
Website

Re: [Solved] Listing uncategorized content

Bloke wrote #324906:

Just need to remember to omit that value (probably via exclude) if making category lists.

Good point. Thinking aloud. – if it were assigned by default upon creation, I’d lean to having it be as unobtrusive as possible – since it effectively represents a null. Ideally the uncategorized value would be excluded by default, and only show when explicitly called for.

*edit – which would make it backward compatible in behavior.

Last edited by maverick (2020-07-27 14:12:11)

Offline

#10 2020-07-27 14:54:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: [Solved] Listing uncategorized content

maverick wrote #324910:

if it were assigned by default upon creation, I’d lean to having it be as unobtrusive as possible – since it effectively represents a null.

Ah, wires crossed. I thought you meant could I (on that site) create a category to represent ‘uncategorized’ and move all the unset content to that category so I could extract it. The answer to that is ‘yes’.

If you mean, could we (Textpattern) by default have a category called Uncategorized which is effectively the same as ‘empty’ today but actually has a value that can be used in category attributes (e.g. <txp:file_download_list category="uncategorized" /> then I’d lean towards ‘no’ unless someone can convince me it’s a good idea.

It involves:

  • Another ‘magic’ value (‘uncategorized’ or ‘none’ or whatever) which means it becomes a reserved word that needs documenting.
  • Other fairly hefty code and documentation changes.
  • A new common lang string so it can be displayed on both front- end back-ends.
  • Anyone who currently used the ‘empty comma’ trick would need to change their code.

Empty (no value) is unambiguous: “Not assigned to a category.” The only tricky issue is that nothing is very difficult to interrogate in computers because it means different things to different people. Even in PHP, sometimes an empty string is regarded as ‘nothing’ and other times it’s regarded as ‘something’ (compared to being null). Zero, likewise. So it depends on context a lot of the time. Heck, even in maths, 00 tends to 1!

Our attributes behave in different ways too. Sometimes if you omit an attribute (do nothing) you get ‘everything’ back (e.g. <txp:images />). Sometimes you get some default behaviour (e.g. limit="10" in <txp:article />). Sometimes, setting an attribute empty turns off default behaviour (e.g. the old escape attribute). These inconsistencies are for the good of convention and to enable the tags to cater for 80% of use cases with the fewest attributes.

I don’t really have a point here, just saying that ‘nothing’ or ‘empty’ means different things depending on where it’s used. So if we were to introduce some kind of magic value do we allow category="null" or “uncategorized” or “empty” or “unset” or “0” or “” or “none” or “default” (like we do for <txp:if_section>) or “{empty}” or prefix the value to minimise the risk of clashing with someone else’s actual category name? Whichever we choose becomes unusable for users.

I’d need convincing this was a solid idea and be able to do it in a clean preferably backwards-compatible manner before moving forward.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB