Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/08/2013, 09:54
Avatar de engonga
engonga
Usuario no validado
 
Fecha de Ingreso: marzo-2002
Ubicación: Buenos Aires
Mensajes: 1.300
Antigüedad: 22 años, 1 mes
Puntos: 8
Respuesta: short code gallery en un post personalizado

la verdad es que si que funciona pero he añadido un filtro para modificar la galeria y cuando lo activo no me funcion


esto es la personalización de la galería

Código PHP:
// http://wordpress.stackexchange.com/questions/4343/how-to-customise-the-output-of-the-wp-image-gallery-shortcode-from-a-plugin

add_filter'post_gallery''my_post_gallery'102);
function 
my_post_gallery$output$attr) {
    global 
$post$post_type $wp_locale;
    
    static 
$instance 0;
    
$instance++;
    
    
// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
    
if ( isset( $attr['orderby'] ) ) {
        
$attr['orderby'] = sanitize_sql_orderby$attr['orderby'] );
        if ( !
$attr['orderby'] )
        unset( 
$attr['orderby'] );
    }
    
    
extract(shortcode_atts(array(
    
'order'      => 'ASC',
    
'orderby'    => 'menu_order ID',
    
'id'         => $post->ID,
    
'itemtag'    => 'DIV',
    
'icontag'    => 'SPAN',
    
'captiontag' => 'P',
    
'columns'    => 1,
    
'size'       => 'large'// medium, large, full, 
    
'include'    => '',
    
'exclude'    => ''
    
), $attr));
    
    
$id intval($id);
    if ( 
'RAND' == $order )
    
$orderby 'none';
    
    
$galeriatipo esc_attr($tipogal);
    
    
/*if ( $galeriatipo == "comun"){
        echo "se esta mostrando la galeria común    ";
        }else{
        echo "la galeria es especial   ";
    }*/
    
    
if ( !empty($include) ) {
        
$include preg_replace'/[^0-9,]+/'''$include );
        
$_attachments get_posts( array('include' => $include'post_status' => 'inherit''post_type' => 'attachment''post_mime_type' => 'image''order' => $order'orderby' => $orderby) );
        
        
$attachments = array();
        foreach ( 
$_attachments as $key => $val ) {
            
$attachments[$val->ID] = $_attachments[$key];
        }
    } elseif ( !empty(
$exclude) ) {
        
$exclude preg_replace'/[^0-9,]+/'''$exclude );
        
$attachments get_children( array('post_parent' => $id'exclude' => $exclude'post_status' => 'inherit''post_type' => 'attachment''post_mime_type' => 'image''order' => $order'orderby' => $orderby) );
    } else {
        
$attachments get_children( array('post_parent' => $id'post_status' => 'inherit''post_type' => 'attachment''post_mime_type' => 'image''order' => $order'orderby' => $orderby) );
    }
    
    if ( empty(
$attachments) )
    return 
'';
    
    if ( 
is_feed() ) {
        
$output "\n";
        foreach ( 
$attachments as $att_id => $attachment )
        
$output .= wp_get_attachment_link($att_id$sizetrue) . "\n";
        return 
$output;
    }
    
    
$numero_imagenes count($attachments);
    
    
    
    
$itemtag tag_escape($itemtag);
    
$captiontag tag_escape($captiontag);
    
$columns intval($columns);
    
$itemwidth $columns floor(100/$columns) : 100;
    
$float is_rtl() ? 'right' 'left';
    
$anchocontenedor $numero_imagenes 940
    
    
$selector "gallery-{$instance}";
    
    
$output apply_filters('gallery_style''<!-- see gallery_shortcode() in wp-includes/media.php -->
    
    
    <div class="slider-wrapper theme-default">
    
    <div id="slider" class="nivoSlider">
    '
);
    
    
$i 0;
    foreach ( 
$attachments as $id => $attachment ) {        
        
//$link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
        
$link =  wp_get_attachment_image($id$sizetruefalse) ;
        
        
        
// para saber el ancho de la imagen
        
$image_attributes wp_get_attachment_image_src$id$size ); // returns an array el [1] es l'amplada http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src
        
        //$output .= "<{$itemtag} id='gallery-item-$i' class='slide'>\n";
        
$output .= $link ."\n";
        
/*$output .= "
            <{$icontag} class='gallery-icon'>
            $link
        </{$icontag}>";*/
        //$output .= "</{$itemtag}>\n";
        //if ( $columns > 0 && ++$i % $columns == 0 )
        //$output .="<br style="clear: both" />';
    
}
    
    
$output .= "
    </div> <!-- end of slider -->\n
    </div> <!-- end of  id='slider-wrapper theme-default' -->\n"
;
    
    return 
$output;