• Resolved traumm

    (@traumm)


    Hi all,

    I’m planning on using WP’s new media manager / gallery in order to control a custom gallery that will be different on each page.

    However, instead of add the new gallery to the content area, it needs to appear elsewhere on the page.

    I’ve got this working firstly by removing the default Gallery shortcode (to prevent it from showing up in the front-end content area)

    Then in my functions file I’ve added this:

    function customGallery($output, $attr) {
    
        	$order = 'DESC';
    
        	$orderby = 'post__in';
        	$include = $attr['ids'];
    
        	$_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];
        		}
    
        	if ( empty($attachments) ) return;
    
        	foreach ( $attachments as $id => $attachment ) { ?>
        		<img src="<?php echo wp_get_attachment_url( $id ); ?>" alt="<?php echo $attachment->post_excerpt; ?>" />
        	<?php }
        }

    My question is, what am I passing to this function in my template?

    At the moment this snippet in page.php gets all image attachments, not just the ones attached to the page in question.

    <?php customGallery($output, $attr); ?>

    Hopefully someone can help here – am assuming it’s a case of passing an array of page-specific values to $attr

    Any help much appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Gallery (using WordPress' native gallery functionality)’ is closed to new replies.