Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-03-20 20:07:17

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

display number of images inside an image category

OK, I thought this might be a simple thing, but it’s actually turned into somewhat of a mystery. Can anyone provide a means of displaying the number of images in any given image category? So if I had a category called “My Pics”, and it had 12 photos in there, I would need to display the number “12”. (Assume there would be lots of different categories.) Hope that makes sense.

I tried the amazing smd_gallery, but that cannot do this out of the box. I also found glx_num_images, but the download link is dead so I have no means of testing.

Last edited by kevinpotts (2009-03-20 20:08:06)


Kevin
(graphicpush)

Offline

#2 2009-03-20 22:14:10

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

Re: display number of images inside an image category

D’oh! Doesn’t help if you have more than one category still, but at least it solves the “how do I do it only once” thing

Last edited by Bloke (2009-03-20 22:15:26)


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

#3 2009-03-20 22:32:00

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: display number of images inside an image category

smd_query or jmd_count can count images too.

Offline

#4 2009-03-21 01:05:07

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

Re: display number of images inside an image category

jm wrote:

smd_query or jmd_count can count images too.

These appear very powerful, but I do not understand how to target what I want. For instance, <txp:jmd_count table="txp_image" /> correctly outputs the total number of images, but I do not get how to drill into a specific image category using the where attribute. Any direction would be most appreciated.


Kevin
(graphicpush)

Offline

#5 2009-03-21 01:30:42

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: display number of images inside an image category

Did you look at plugin help?

<txp:jmd_count table="txp_image" where="category = minecategory"/>

Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#6 2009-03-21 01:46:48

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

Re: display number of images inside an image category

the_ghost wrote:

Did you look at plugin help?

I did actually. And I tried the exact syntax you provided using my category name (“march-23-2009”), and this is the error I received:

Tag error: <txp:jmd_count table=“txp_image” where=“category = march-23-2009” /> -> Textpattern Warning: Unknown column ‘march’ in ‘where clause’
select count(*) from txp_image where category = march-23-2009 on line 82


Kevin
(graphicpush)

Offline

#7 2009-03-21 08:46:11

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: display number of images inside an image category

Try to surround category’s name with quotes:

<txp:jmd_count table=“txp_image” where=“category = 'march-23-2009' ” />

Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#8 2009-03-21 14:24:32

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

Re: display number of images inside an image category

Try to surround category’s name with quotes:

That worked perfectly. Here’s something interesting though. Because it is being called from an article form, the value of the category name has to be dynamic. In my current set-up, the category name matches the URL title of the article, so the article for March 23, 2009 has an associated image category called March 23, 2009. In other areas of functionality, I am using the tag <txp:article_url_title /> to call the category name. Anyway, so I tried this:

<txp:jmd_count table="txp_image" where="category = '<txp:article_url_title />' " />

Interestingly, the new TXP tag parsing engine does not work as expected here; the query looks for an actual category named “<txp:article_url_title />” instead of the value of that tag, which of course fails. However, I tried using good old asy_wondertag, like this:

<txp:asy_wondertag><txp:jmd_count table="txp_image" where="category = '<txp:article_url_title />' " /></txp:asy_wondertag>

… and it works perfectly. There’s no school like the old school. Every article form is correctly counting the number of images in the associated gallery.

Thank you everyone for your help.


Kevin
(graphicpush)

Offline

#9 2009-03-21 14:28:44

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: display number of images inside an image category

Try this:

<txp:jmd_count table="txp_image" where='category = <txp:article_url_title />' />

(edited because I still got the quotes wrong…)

Last edited by els (2009-03-21 14:31:42)

Offline

#10 2009-03-21 14:40:32

kevinpotts
Member
From: Ghost Coast
Registered: 2004-12-07
Posts: 370

Re: display number of images inside an image category

<txp:jmd_count table="txp_image" where='category = <txp:article_url_title />' />

Tried it and it does not work. It does not throw an error, it just does not render any value.


Kevin
(graphicpush)

Offline

#11 2009-03-21 15:36:30

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

Re: display number of images inside an image category

Getting into the realm of guessing here: one reason why it works with asy_wondertag and not with the new parser is that the single quotes are needed for the where MySQL query and also denote “parse this tag” for the parser. What happens if you use two sets of single quotes, either next to each other or around the where and around the article_url?


TXP Builders – finely-crafted code, design and txp

Offline

#12 2009-03-21 15:50:28

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: display number of images inside an image category

Don’t forget to surround category name with quotes again :) And look in full tag-trace (site working mode set to Debug) – you can see which sql query is perfomed.

<txp:jmd_count table="txp_image" where='category = "<txp:article_url_title />" ' />

Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

Board footer

Powered by FluxBB