Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-12-19 10:47:35

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

count images in a category

I am trying to display the number of images belonging to a specific category.

<txp:php>echo safe_count('txp_image', "category = 'img_cat'");</txp:php> returns a parse error. Can someone help?


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

Offline

#2 2012-12-19 12:28:57

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: count images in a category

Hi Yiannis,

for whatever reason (and I’m curious why!) that code won’t work if put straight in an article, but works in a page. Should you, however, need it in an article, create a form containing that code and call the form from your article. Edit: Textile’s == escape also worked.

Last edited by uli (2012-12-19 13:40:35)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#3 2012-12-19 12:34:21

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

Re: count images in a category

uli wrote:

won’t work if put straight in an article

Textile getting in the way maybe?


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 2012-12-19 12:41:04

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

Re: count images in a category

It works in articles for me. Are you sure to have “Allowed PHP in articles”?

Offline

#5 2012-12-19 12:44:13

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: count images in a category

Bloke wrote:

Textile getting in the way maybe?

I hadn’t expected that with the error

Parse error: syntax error, unexpected $end, expecting T_STRING or T_VARIABLE or '$' in [snip]textpattern/publish/taghandlers.php(3748) : eval()'d code on line 1

But you’re right.
I just don’t get that a <txp:php> is eaten by Textile, while a <txp:output_form /> isn’t.

Last edited by uli (2012-12-19 12:44:32)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#6 2012-12-19 12:46:47

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: count images in a category

etc wrote:

Are you sure to have “Allowed PHP in articles”?

Yup. Is there maybe a difference between 441 and 454 in this behaviour?
Edit: Probably also in the Textile versions.

Last edited by uli (2012-12-19 13:38:54)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#7 2012-12-19 13:30:42

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

Re: count images in a category

For me neither the php nor the output form (containing the code) is parsed in an article. I also have php enabled for both pages and articles.


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

Offline

#8 2012-12-19 13:37:25

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: count images in a category

Strange. Did you try embedding the tags in two of Textiles ==? Worked for me.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#9 2012-12-19 14:21:51

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

Re: count images in a category

colak wrote:

For me neither the php nor the output form (containing the code) is parsed in an article. I also have php enabled for both pages and articles.

Yiannis, have you tried to “Leave text untouched”? If it works, then == or notextile. should help. Otherwise, there might be some typos in the article that bother the parser, but then good luck in hunting :)

Offline

#10 2012-12-19 18:54:57

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

Re: count images in a category

== around the php does not work but notextile.. does the trick… Thanks for all you help.


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

Offline

Board footer

Powered by FluxBB