
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 1.05 KB | hits: 12 | expires: Never
Wordpress - check if loop contains posts with attachments?
function gotImages()
{
$attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image') );
return ( !empty($attachments) ? true : false );
}
function gotImages()
{
global $wp_query;
$posts = $wp_query->posts;
if ( empty( $posts ) )
return $posts;
$searchImages = '~<img [^>]* />~';
foreach ($posts as $post) {
$content = $post->post_content;
preg_match_all( $searchImages, $content, $countImages );
$images += count($countImages[0]);
}
return ( $images >= 1 ? true : false );
}
if( !is_admin() && gotImages() == true ) :
wp_register_script('fancybox', get_stylesheet_directory_uri() . '/libs/fancybox/jquery.fancybox.pack.js', array('jquery'), false, true);
wp_register_script('fancybox.init', get_stylesheet_directory_uri() . '/js/init/lightbox.init', array('fancybox'), false, true);
wp_enqueue_script('fancybox');
wp_enqueue_script('fancybox.init');
endif;