Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-07-23 13:04:49

Cedric
Archived Plugin Author
From: Germany
Registered: 2009-05-26
Posts: 13
Website

ckr_image_count - Counts images and provides a conditional tag

This plugin provides two new tags:
  • <txp:ckr_image_count /> – output the count of all images
  • <txp:ckr_if_image_count></txp:ckr_if_image_count> – a conditional tag

Counting images with ckr_image_count

Place the <txp:ckr_image_count /> tag wherever you want the count to appear. The tag supports one attribute called category. If set to a category’s name, only images within will be counted.

Examples:

<txp:ckr_image_count /> – displays the count of all images
<txp:ckr_image_count category="mycategory" /> – displays the count of images within given category

Using the conditional tag ckr_if_image_count

Place the <txp:ckr_if_image_count></txp:ckr_if_image_count> tags wherever you want to check for the given condition. The tag supports the category attribute as well and in addition to it the following four: min, max, equal, not. At least one of them must be given, only min and max can be combined. Furthermore it offers support for Textpattern’s internal <txp:else /> tag.

Simple examples:

<txp:ckr_if_image_count min="3">
    At least 3 images available.
</txp:ckr_if_image_count>
<txp:ckr_if_image_count max="5">
    There are not more than 5 images available.
</txp:ckr_if_image_count>

Examples for combining category and any condition:

<txp:ckr_if_image_count category="mycategory" equal="5">
    Category "mycategory" contains 5 images.
</txp:ckr_if_image_count>
<txp:ckr_if_image_count category="mycategory" not="5">
    Category "mycategory" contains anything but 5 images.
</txp:ckr_if_image_count>

Examples for combining min and max attribute:

<txp:ckr_if_image_count min="1" max="5">
    There's at least more than 1 image, but less (or equal) than 5 images.
</txp:ckr_if_image_count>
<txp:ckr_if_image_count category="mycategory" min="1" max="5">
    Category "mycategory" contains more than 1 image, but less (or equal) than 5 images.
</txp:ckr_if_image_count>

Example for using the txp:else block:

<txp:ckr_if_image_count equal="7">
    There are exactly 7 images available.
<txp:else />
    There are anything but 7 images available.
</txp:ckr_if_image_count>

Combining ckr_if_image_count with ckr_if_image_count

Of course you can combine both tags in case you need to master a complex situation. Take a look at the following example to get a brief overview of what can be accomplished.

Example:

<txp:ckr_if_image_count category="mycategory" min="3">
     Category "mycategory" contains at least <txp:ckr_image_count category="mycategory" /> images.
<txp:else />
    Category "mycategory" doesn't contain enough images.
    At least 3 are needed.
</txp:ckr_if_image_count>

About this plugin

Author: Cedric Kastner
Version: 0.1
Download: http://nur-text.de/download/ckr_image_count_v0.1.txt
Textpattern.org: http://textpattern.org/plugins/1109/ckr_image_count
Last modification: 2009/07/23, 13:23 CEST

Last edited by Cedric (2009-07-23 15:01:19)

Offline

#2 2009-07-23 13:24:44

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

Re: ckr_image_count - Counts images and provides a conditional tag

Brilliant stuff. This should become a very useful companion to smd_gallery. Inside its form or countform, you could add some variant of:

<txp:smd_gallery category="cat1, cat2, cat3">
   <txp:ckr_image_count category="{category}" />
</txp:smd_gallery>

to show the counts for each category at strategic places in your gallery. Nice one, thanks :-)

P.S. Should this thread be moved to the Plugin Author Support forum?

Last edited by Bloke (2009-07-23 13:26:21)


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-07-23 15:00:17

Cedric
Archived Plugin Author
From: Germany
Registered: 2009-05-26
Posts: 13
Website

Re: ckr_image_count - Counts images and provides a conditional tag

Hi Stef,

I needed the plugin to get the image count for later use with jCarouselLite. I wanted to have the carousel enabled if there are > X images.
Would be great if someone could move the thread. Thanks :)

Cheers,
Cedric

Last edited by Cedric (2009-07-23 15:00:43)

Offline

#4 2009-07-29 17:16:07

photonomad
Member
Registered: 2005-09-10
Posts: 290
Website

Re: ckr_image_count - Counts images and provides a conditional tag

Cedric: This is a great plugin. I too am using jCarouselLite and I would like to use ckr_image_count to enable or disable it depending on the number of images. Is there any way to check for the article image count for use in an article context? My galleries consist of a number of images assigned to an article (not an image category).

glx_image_count would do what I want — but unfortunately it is archived with a dead link.

I imagine that I might be able to get smd_if to test for the number of image id’s in my Article Image field. Stef’s plugins are powerful – I just wish I had more of a programmer’s brain to figure them out! : )

Offline

#5 2009-07-29 17:29:29

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

Re: ckr_image_count - Counts images and provides a conditional tag

photonomad wrote:

My galleries consist of a number of images assigned to an article (not an image category)… I imagine that I might be able to get smd_if to test for the number of image id’s in my Article Image field.

Without trying to hijack this thread, you’re right that you can do that with smd_if, since smd_gallery has a replacement tag that returns the total number of images in the set:

<txp:smd_gallery id="?article_image">
   <!-- is the total number of images in the gallery greater than 5? -->
   <txp:smd_if field="{totalimages}" operator="gt" value="5">
      <txp:thumbnail id="{id}" />
   </txp:smd_if>
</txp:smd_gallery>

Does that get you close?


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

#6 2009-07-29 17:39:18

photonomad
Member
Registered: 2005-09-10
Posts: 290
Website

Re: ckr_image_count - Counts images and provides a conditional tag

Thanks Stef! I have been using hak_article_image for this particular gallery setup, but I will install smd_gallery and give it a whirl! Will edit this post when I have it figured out.

moved this conversation to the smd_gallery forum

Last edited by photonomad (2009-07-29 22:48:26)

Offline

#7 2013-04-04 15:22:05

jens31
Plugin Author
From: munich / dtschermani
Registered: 2008-08-25
Posts: 183
Website

Re: ckr_image_count - Counts images and provides a conditional tag

hi

dead links all over the place..
anybody has a copy and can reup this fine piece of code..?

Offline

#8 2013-04-04 17:04:36

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

Re: ckr_image_count - Counts images and provides a conditional tag

Jens, I think you can achieve the same (and a lot more) with jmd_count.

Last edited by uli (2013-04-04 17:04:59)


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

Offline

#9 2013-04-05 07:42:01

jens31
Plugin Author
From: munich / dtschermani
Registered: 2008-08-25
Posts: 183
Website

Re: ckr_image_count - Counts images and provides a conditional tag

thanks for the reply uli.
i ended up using jmd_count and it works like a charm.

Offline

Board footer

Powered by FluxBB