Support » Plugins » Hacks » Automating Galleries into Posts

  • I’m looking to automate my galleries into posts. Basically how I am hoping to accomplish this is by having the same name for both the gallery title and the post. The code i would place into the page/post template would seek out any photo galleries that also have the same name as the post title. Once it finds it it would copy the post ID and then paste it into the short code within the code to automate putting galleries into posts.

    This is beyond my skill set but I think it should be possible and I was hoping someone else with more experience could help me put the pieces together. The gallery plugin i’m using is FIAgallery.

    I need a script that pulls the gallery ID and saves that ID number to post in the executing echo line below – which I’m positive isn’t going to do what I want but I’m putting it here for a visual representation.

    <?php echo do_shortcode('[flagallery gid='.get_gallery_meta($post->ID) .get_the_title();']'); ?>
Viewing 1 replies (of 1 total)
  • I found a post that is similar to what I’m doing. In this the code searches a post to see if there are image attachments to that post. If there are it echos the shortcode to put the gallery in the post.

    I want to check if the post title equals the gallery title and if so it gets the gallery ID and echoes it into the code so it will post the correct gallery into each post. Hope that makes sense? Here’s the example that checks if a post has image attachments.

    /*  Function to show the post gallery just if it exists  */
    function show_gallery( $post_id ) {
    	$args = array(
    		'post_type' => 'attachment',
    		'numberposts' => null,
    		'post_status' => null,
    		'post_parent' => $post_id
    	$attachments = get_posts( $args );
    	$is_images = false;
    	// make sure the attachment(s) are image(s). otherwise, ignore them
    	foreach( $attachments as $item ) {
    		$mime_types = explode( "/", get_post_mime_type( $item->ID ) );
    		if ( in_array( 'image', $mime_types ) ) {
    			$is_images = true;
    	if ( $is_images )
    		echo do_shortcode( '[gallery columns="3"]' );
    		echo '<p id="no_gallery">' . __( 'Sorry, no photos for this item.' ) . '</p>';
Viewing 1 replies (of 1 total)
  • The topic ‘Automating Galleries into Posts’ is closed to new replies.