Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add webcomic_count template tag.

This tag should be useful for users that want to do different things
with their webcomics based on how many attachments the webcomic post
has.
  • Loading branch information...
commit ac07c749ece3c6bdc509cc672e82a9c8608b31c7 1 parent 3e41e1e
Michael Sisk authored
Showing with 38 additions and 0 deletions.
  1. +38 −0 -/php/tags.php
View
38 -/php/tags.php
@@ -2,6 +2,7 @@
/** Contains the WebcomicTag class and template tag functions.
*
* @package Webcomic
+ * @todo get_webcomic_attachments_number
*/
/** Handle custom template tag functionality.
@@ -455,6 +456,18 @@ public static function the_webcomic( $size = 'full', $relative = '', $in_same_te
}
}
+ /** Return the number of Webcomic-recognized attachments.
+ *
+ * @param mixed The post object or ID to retrieve the attachment count for.
+ * @return integer
+ * @filter integer webcomic_count Filters the webcomic-recognized attachment count returned by `webcomic_count`.
+ */
+ public static function webcomic_count( $the_post = false ) {
+ if ( $the_post = get_post( $the_post ) and $attachments = self::get_attachments( $the_post->ID ) ) {
+ return apply_filters( 'webcomic_count', count( $attachments ), $the_post );
+ }
+ }
+
/** Return an array of webomics related to the current webcomic.
*
* @param boolean $storylines Match based on storylines.
@@ -3328,6 +3341,31 @@ function the_webcomic( $size = 'full', $relative = '', $in_same_term = false, $e
}
}
+if ( !function_exists( 'webcomic_count' ) ) {
+ /** Return the number of Webcomic-recognized attachments.
+ *
+ * <code class="php">
+ * // display the number of Webcomic-recognized attachments found on the current post
+ * echo webcomic_count();
+ *
+ * if ( 1 < webcomic_count() ) {
+ * // the current post has more than one Webcomic-recognized attachment
+ * }
+ *
+ * if ( 3 === webcomic_count( 42 ) {
+ * // the post with an ID of 42 has exactly three Webcomic-recognized attachments.
+ * }
+ * </code>
+ *
+ * @param mixed The post object or ID to retrieve the attachment count for.
+ * @return integer
+ * @uses WebcomicTag::webcomic_count()
+ */
+ function webcomic_count( $the_post = false ) {
+ return WebcomicTag::webcomic_count( $the_post );
+ }
+}
+
if ( !function_exists( 'the_related_webcomics' ) ) {
/** Render a formatted list of related webcomics.
*
Please sign in to comment.
Something went wrong with that request. Please try again.