rkb81
9/14/2011 - 10:57 AM

HTML 5 WordPress Gallery

HTML 5 WordPress Gallery

/* Novo formato da galeria de imagens */
	remove_shortcode('gallery');
	add_shortcode('gallery','nova_galeria');
	 
	function nova_galeria($atts, $content = null) {
		extract(shortcode_atts(array(
			'small_image' => 'thumbnail',
			'large_image' => 'large',
			'captions' => 'figcaption',
			'link' => '',
			'link_title' => '',
			'lightbox_group' => '',
			'class' => '',
			'parent_wrap' => 'ul',
			'item_wrap' => 'li',
			'child_wrap' => 'figure',
			'id' => ''
			), $atts));
 
		global $post;
		$images = get_posts( 'post_type=attachment&post_mime_type=image&numberposts=-1&post_parent='.$post->ID.'&orderby=menu_order&order=ASC&exclude='. get_post_thumbnail_id( $post->ID ) .' ');
		if ( empty($images) ) {
				echo '<p>Nenhuma imagem foi encontrada</p>';
		} else {
			/* $id = ( $id != '' ) ? ' id="'.$id.'"' : '';
			$class = ( $class != '' ) ? ' class="'.$class.'"' : ''; */
			$html = ($parent_wrap!='')?"<{$parent_wrap} class='gallery'>\r\n":'';
			$lightbox = ($lightbox_group=='')?'':' rel="lightbox['.$lightbox_group.']"';
			foreach ( $images as $image ) {
				//$image_title = ($link_title=='true')?' title="'.ucwords(str_replace('-',' ',$image->post_title)).'"':'';
				$alt = ($link_title=='true')?' alt="'.ucwords(str_replace('-',' ',$image->post_title)).'"':'';
				$image_alt = ($alt!='')?' alt="'.$alt.'"':'';
				$lrg_image = wp_get_attachment_image_src($image->ID,$large_image);
				$thumb_image = wp_get_attachment_image_src( $image->ID, $small_image );
				$html .= ($item_wrap!='')?"<{$item_wrap}>\r\n":'';
				$html .= ($child_wrap!='')?"<{$child_wrap}>\r\n":'';
				$html .= "\t<a href=\"{$lrg_image[0]}\"{$lightbox} id=\"img-".$image->ID."\">";
				$html .= '<img src="'.$thumb_image[0].'" width="'.$thumb_image[1].'" height="'.$thumb_image[2].'"'.$alt.' />';
				$html .= "</a>\r\n";
				$html .= ($captions=='true')?"\t<captions>".ucwords(str_replace('-',' ',$image->post_title))."</captions>\r\n":'';
				$html .= ($child_wrap!='')?"</{$child_wrap}>\r\n":'';
				$html .= ($item_wrap!='')?"</{$item_wrap}>\r\n":'';
				$lrg_image = ''; }
			$html .= ($parent_wrap!='')?"</{$parent_wrap}>":'';
			return $html; }
	}
/* Novo formato da galeria de imagens */
	remove_shortcode('gallery');
	add_shortcode('gallery','nova_galeria');
	 
	function nova_galeria($atts, $content = null) {
		extract(shortcode_atts(array(
			'small_image' => 'thumbnail',
			'large_image' => 'large',
			'captions' => 'figcaption',
			'link' => '',
			'link_title' => '',
			'lightbox_group' => '',
			'class' => '',
			'parent_wrap' => 'ul',
			'item_wrap' => 'li',
			'child_wrap' => 'figure',
			'id' => ''
			), $atts));
 
		global $post;
		$images = get_posts( 'post_type=attachment&post_mime_type=image&numberposts=-1&post_parent='.$post->ID.'&orderby=menu_order&order=ASC');
		if ( empty($images) ) {
				echo '<p>Nenhuma imagem foi encontrada</p>';
		} else {
			/* $id = ( $id != '' ) ? ' id="'.$id.'"' : '';
			$class = ( $class != '' ) ? ' class="'.$class.'"' : ''; */
			$html = ($parent_wrap!='')?"<{$parent_wrap} class='gallery'>\r\n":'';
			$lightbox = ($lightbox_group=='')?'':' rel="lightbox['.$lightbox_group.']"';
			foreach ( $images as $image ) {
				//$image_title = ($link_title=='true')?' title="'.ucwords(str_replace('-',' ',$image->post_title)).'"':'';
				$alt = ($link_title=='true')?' alt="'.ucwords(str_replace('-',' ',$image->post_title)).'"':'';
				$image_alt = ($alt!='')?' alt="'.$alt.'"':'';
				$lrg_image = wp_get_attachment_image_src($image->ID,$large_image);
				$thumb_image = wp_get_attachment_image_src( $image->ID, $small_image );
				$html .= ($item_wrap!='')?"<{$item_wrap}>\r\n":'';
				$html .= ($child_wrap!='')?"<{$child_wrap}>\r\n":'';
				$html .= "\t<a href=\"{$lrg_image[0]}\"{$lightbox} id=\"img-".$image->ID."\">";
				$html .= '<img src="'.$thumb_image[0].'" width="'.$thumb_image[1].'" height="'.$thumb_image[2].'"'.$alt.' />';
				$html .= "</a>\r\n";
				$html .= ($captions=='true')?"\t<captions>".ucwords(str_replace('-',' ',$image->post_title))."</captions>\r\n":'';
				$html .= ($child_wrap!='')?"</{$child_wrap}>\r\n":'';
				$html .= ($item_wrap!='')?"</{$item_wrap}>\r\n":'';
				$lrg_image = ''; }
			$html .= ($parent_wrap!='')?"</{$parent_wrap}>":'';
			return $html; }
	}