Closed cleverchicken closed 11 years ago
Unless there is a better way, I'll just use: if( WebcomicTag::webcomic_dropdown_collections(array( 'collection' => $collection['id'])) { // do stuff } It seems to work.
There are several ways to do this (including the one you posted, though I'm not sure I'd actually use that one). If we're talking about a template that uses a custom loop, you should be able to check whether or not there are any posts with the have_posts()
function, like:
$webocmics = new WP_Query( array( 'post_type' => 'webcomic42' ) );
if ( $webcomics->have_posts() ) :
/* only do this if webcomic42 has published webcomics */
endif;
Alternatively, the WordPress function wp_count_posts
might be exactly what you need and should work in almost any situation. You can use it like:
$webcomics = wp_count_posts( 'webcomic42' ); // or you could use get_webcomic_collection() to grab whatever the current collection is
if ( $webcomics->publish ) :
/* only do stuff if there are published webcomics in webcomic42 */
endif;
Perfect! Your second solution works beautifully. Thanks a ton. Again, excellent plugin, sir.
Thanks!
I've been setting up my site and using the template tags to set up a webcomic directory (I have multiple webcomics). I realized that if a collection was empty, my template would still try to pull the data of that collection and the latest webcomic thumbnail. I wanted to setup an if statement to determine if the collection had any webcomics at all and if it doesn't (webcomic count = 0) then don't display anything.
Problem is I can't seem to find a way to count the number of webcomics in a collection. Am I overlooking a template tag or another solution to this? Any ideas would be appreciated!
Great plugin by the way!