Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add webcomic-attachment count class to post_class.

  • Loading branch information...
commit 3e41e1ec1f8fb1ebd33671f0f972f3b500711d92 1 parent 00bf0a9
Michael Sisk authored
Showing with 19 additions and 0 deletions.
  1. +19 −0 webcomic.php
19 webcomic.php
View
@@ -107,6 +107,7 @@ class Webcomic {
* @uses Webcomic::get_terms()
* @uses Webcomic::stylesheet()
* @uses Webcomic::body_class()
+ * @uses Webcomic::post_class()
* @uses Webcomic::get_the_terms()
* @uses Webcomic::post_type_link()
* @uses Webcomic::the_content_feed()
@@ -148,6 +149,7 @@ public function __construct() {
add_filter( 'get_terms', array( $this, 'get_terms' ), 10, 3 );
add_filter( 'stylesheet', array( $this, 'stylesheet' ), 10, 1 );
add_filter( 'body_class', array( $this, 'body_class' ), 10, 2 );
+ add_filter( 'post_class', array( $this, 'post_class' ), 10, 3 );
add_filter( 'get_the_terms', array( $this, 'get_the_terms' ), 10, 3 );
add_action( 'post_type_link', array( $this, 'post_type_link' ), 10, 4 );
add_filter( 'the_content_feed', array( $this, 'the_content_feed' ), 10, 1 );
@@ -1164,6 +1166,23 @@ public function body_class( $classes, $class ) {
return $classes;
}
+ /** Add webcomic classes to posts.
+ *
+ * @param array $classes Array of post classes.
+ * @param mixed $class Additional classes passed to post_class().
+ * @param integer $id Post ID.
+ * @return array
+ * @uses Webcomic::get_attachments()
+ * @hook post_class
+ */
+ public function post_class( $classes, $class, $id ) {
+ if ( preg_match( '/^webcomic\d+$/', get_post_type( $id ) ) and $attachments = self::get_attachments( $id ) ) {
+ $classes[] = sprintf( 'webcomic-attachments-%s', count( $attachments ) );
+ }
+
+ return $classes;
+ }
+
/** Add a webcomic_image property to term objects.
*
* @param array $terms Array of retrieved terms.
Please sign in to comment.
Something went wrong with that request. Please try again.