Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-04-23 14:26:31

Karsten
Member
From: Leiden, Netherlands
Registered: 2011-04-24
Posts: 47
Website

Category list broken after update

Hi guys,

My website has a list of links that pull in articles from multiple categories… for example:

<txp:category name=“cats,dogs”>Animals</txp:category>

This used to result in a combined list of articles classified as either cats or dogs.

After running the latest TXP update, I noticed this does not work anymore.

To see the site where it all goes wrong: http://www.sidestone.com/library/

It’s the website of my academic publishing company… I use several different categories to classify our books, but in the “browse by subject” list (on the right) I chose to combine several categories for convenience sake. This used to work fine, but see what happens when you click for example on “Anthropology”. The resulting URL:

http://www.sidestone.com/library/?c=anthropology%2Crmv%2Cmemorytraps%2Canthroarchaeo

does not work, where it used to provide a list of all books as either of these categories.

Does anyone know what is going wrong an how to fix it?

Last edited by Karsten (2013-04-23 14:27:49)

Offline

#2 2013-04-23 14:42:07

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,547
Website GitHub Twitter

Re: Category list broken after update

Hi

The name attribute of txp:category must have only one category, i wonder how it worked before! it was a miracle!

Offline

#3 2013-04-23 14:51:38

Karsten
Member
From: Leiden, Netherlands
Registered: 2011-04-24
Posts: 47
Website

Re: Category list broken after update

This used to work,

the comma separated list is suggested in the following article:

http://www.textpattern.net/wiki/index.php?title=if_category

I would really like to know if it is still possible to somehow create a combined list of articles belonging to several different categories

Any ideas anyone?

Offline

#4 2013-04-23 18:20:48

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Category list broken after update

Karsten, that type of comma-separated category list has’t been a supported feature. What you have hit is actually a bug, and an exploit.

The category component, and the c URL query parameter, don’t support comma-separated categories. They handle just one value, and expect the given value to contain just one category name. Prior to Textpattern 4.5.0 there was some broken validation code that allowed that comma-separated value to work:

  • The URLs weren’t validated. The URL should give 404 error, but 404 didn’t work messy URLs, just clean counter-parts. The validation code was broken, letting that value get in and be exploited.
  • The invalid category component from the URL was then passed on, even that it wasn’t correct and would cause issues later on (e.g. category tags, page title etc. can not process the value). Some tags do their own processing to the value despite (e.g. the article tag), giving you some output from some tags. Article tag does that just due to article_custom and article using the same base code to process values. The tag invalidly process categories like they were set by a tag attribute.
  • The invalid URL itself is constructed due to the category tag doing no validation; it outputs anything you give it. The tag actually expects you are giving it a single category, but uses the value anyway due to the lacking validation. You can see that by trying to output a title for instance. It gives you nothing.

This, outside from the category tag, was fixed in Textpattern 4.5.0, and no longer can be exploited. The category name in a messy URL is validated, and 404 page is given on error as it does when using a clean URL format.

Karsten wrote:

I would really like to know if it is still possible to somehow create a combined list of articles belonging to several different categories

Natively not really, sorry. You could use your own query parameter and pass it to article_custom’s category attribute.

<txp:adi_gps name="list" quiet="1" />
<txp:article_custom category='<txp:variable name="list" />'>
    <txp:title />
</txp:article_custom>

The above uses adi_gps to extract the category value (?list=category1, category2) from the requested URL. Downfall is that article_custom does not support pagination.

Other options would include from hacks that inject new category value to the article tag, to having a custom listing plugin. E.g.

<!-- Overwrites assigned category with the one from ?list query param. -->

<txp:php>
    global $c;
    $c = txpspecialchars(gps('list'));
</txp:php>

<!-- Render a list normally -->

<txp:article />

This a hack, directly altering internal global variables. As such, it may stop working in the future.

Offline

#5 2013-04-23 19:14:08

Karsten
Member
From: Leiden, Netherlands
Registered: 2011-04-24
Posts: 47
Website

Re: Category list broken after update

Jukka,

First of all thanks for the thorough answer. One of the reasons why I love Textpattern and the community surrounding it!

The article_custom option won’t work for me, as I need pagination, some categories contain a lot of books (I’m happy to say).

The suggested hack is probably a bit too complicated for me, I’m just a simple archaeologists and publisher :)

Perhaps I’ll try to see if there is a workaround in the way I use categories (perhaps install a plugin that allows more categories). Likewise I also can assign a custom field to contain a string of as many categories/keywords as I like. I already created a list-generating-bit of coding that looks for specific keywords anywhere within the contents of a specific custom field….

That one works as follows (quite clever if I may say so myself)

<txp:article_custom section="NAME-OF-SECTION" customfield='%<txp:custom_field name="customfield" />%' 
 pgonly="0" searchall="0" sort="Posted desc" status="4">
 insert form to display selected articles
 </txp:article_custom>

What it effectively does is use the content of the customfield in the present article to call in a list of all articles in any other section that contain the same value (primary key).

I use this on the authors profile page (section= authors) to generate a list of all books this author wrote at the bottom of the page of all books (section = books) where the author of the current author’s page is listed as book-author. By adding the “%” I also retrieve all the books that have multiple authors including the current author (so it effectively only needs to matches part of the value of the customfield in the books section).

I can perhaps do the same by just filling out a list of keywords in a customfield and generate a list that looks for

'%any particular value%'

I’m just thinking “out loud” here and I realize that probably none of the above makes any sense… :) Nonetheless any comments or tips are highly appreciated

And did I mention that you can read almost all of our books for free online at the above mentioned website!

cheers

Last edited by Karsten (2013-04-23 19:20:05)

Offline

#6 2013-04-23 19:56:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,794
Website GitHub

Re: Category list broken after update

Innovative use of tag attributes!

For the record, etc_pagination permits paging in <txp:article_custom> tags so it might be worth a look.

Last edited by Bloke (2013-04-23 19:56:54)


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

#7 2013-04-24 07:57:57

Karsten
Member
From: Leiden, Netherlands
Registered: 2011-04-24
Posts: 47
Website

Re: Category list broken after update

Thanks.

It’s part of my trick of pulling in content from other articles in other sections based of the use of primary keys. It’s very handy as it lets me pull in information on the author (part of article in section author) when I’m displaying the book page (part of section books) and vice versa. As a result, when you visit my website, the content you are looking at is rarely part of only a single article, usually you are looking at all sorts of elements that are pulled in from various other articles in other sections.

I presented a full explanation here: http://forum.textpattern.com/viewtopic.php?id=36651

But thanks for the pagination suggestion, I will look into that.

Another option, and I don’t know if that is possible, is to use the parent-child relations of the categories.

Can anyone tell me if it is possible to use the value of the parent to generate a list that also includes all children?

As far as the example above is concerned would it be possible to have a category ordering as follows

ANIMALS (parent)
> cats (child)
> dogs (child)

and then do the following:

<txp:category name=“animals”>Animals</txp:category>

to generate a list that also includes all articles that were categorized as either cats or dogs, rather than only those that were categorized using the parent “animals”

That would also completely solve my problem.

Last edited by Karsten (2013-04-24 08:01:35)

Offline

#8 2013-04-24 09:30:48

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,547
Website GitHub Twitter

Re: Category list broken after update

Hi try this

<txp:category name=“animals”>Animals</txp:category>
<txp:article_custom category='<txp:category_list parent="animals" break=","><txp:category /></txp:category_list>'>
put here your txp article tag (title, body, ...)
</txp:article_custom>

Offline

#9 2013-04-24 11:27:44

Karsten
Member
From: Leiden, Netherlands
Registered: 2011-04-24
Posts: 47
Website

Re: Category list broken after update

Hi Rabah,

I don’t think that will work, I don’t want to create a list of all animals,
I now use <txp:category name=“animals”>Animals</txp:category> which result in a link that leads to a page with the url www.mysite.com/?c=animals

This page currently only contains articles for which the category was actually set to “animals” – however, I want this page to also include all articles for which the category was set to either of the children of “animals” e.g. dogs, cats, lizzards, etc.

Offline

#10 2013-04-24 12:33:17

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,547
Website GitHub Twitter

Re: Category list broken after update

Hi replace your txp:article in landing page with this:

<txp:article_custom category=’<txp:category_list parent=’‘<txp:category />’‘ break=”,”><txp:category /></txp:category_list>’>
put here your txp article tag (title, body, …)
</txp:article_custom>

NB: the txp:category inside category_list is surrounded by dash dahs (’ ‘) and not a double dash(“)

Offline

#11 2013-04-24 13:35:49

Karsten
Member
From: Leiden, Netherlands
Registered: 2011-04-24
Posts: 47
Website

Re: Category list broken after update

I don’t think that this will work, as there is no actual landing page where I can place this

<txp:category name=“animals”>Animals</txp:category>

results in a dynamic list like this www.mysite.com/parentsection/?c=animals which uses the same form for displaying the list as the parent section.

If I change that to the one you suggested it might be possible to get these links to work, but the articles on the parent section would not display properly.

Ideally you could use a separate form, just as you would with search results like this <txp:category name=“animals” form=“category-display-form”>Animals</txp:category> but as far as I know that is not possible.

Perhaps have a look at the actual page to make it clear:

http://www.sidestone.com/library/

As you see the page contains a full list of ALL e-books, and the category links on the right provide you with a sub-selection of e-book that adhere to a specific, category. Some however are still broken, as they try to pull in multiple categories – which is the reason for this post in the first place.

An alternative would be to replace the categories by a new multiselect customfield (I have that plugin) and use a search string… however… neither custom fields nor categories are included in the search results. If only they would, I could use that to solve the problem….

Last edited by Karsten (2013-04-24 13:37:16)

Offline

#12 2013-04-24 17:29:38

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Category list broken after update

What Rabah suggets, does work. It will list articles from the requested category and from any child category.

Karsten wrote:

Ideally you could use a separate form

That is possible, as it is with search results. Just wrap the code to a if_category statement.

<txp:if_category>
    <!-- On a category page. -->
    <txp:article_custom category='<txp:category_list parent=''<txp:category />'' break=","><txp:category /></txp:category_list>' />
<txp:else />
   <!-- On a normal, non-category page. -->
   <txp:article />
</txp:if_category>

Offline

Board footer

Powered by FluxBB