How to Show Picture Gallery Automatically in WordPress Post

Programming Tutorials – Creating an picture gallery is basic creating the wordpress wallpaper’s theme. Seegatesite article will share how to display the picture gallery automatically in wordpress posts. If you want to create a blog wallpapers and you need to display your images in a professional manner like the gallery look? Most people start looking for a WordPress plugin that will help them to create a gallery in WordPress, you actually don’t need a plugin for this if you know how.

Here is videos preview how picture gallery script is working properly

 Here’s how to display the picture gallery on wordpress post automatically

1. Create php file as gallery-show.php in your themes folder and copy this code below

 <?php if (is_single() ){ global $post; if ($post->post_status == 'publish' ) {
		$imageattach = get_posts( array(
			'post_type' => 'attachment',
			'posts_per_page' => -1,
			'post_parent' => $post->ID,
			'exclude'     => get_post_thumbnail_id()
		) );

		if ( $imageattach ) { ?>

<h3 class="gallery-title">Gallery of  <?php the_title(); ?></h3>

<ul class="single-gallery">		
			<?php foreach ( $imageattach as $imageatt ) {
				echo '

<li class="gallery-items">';
					echo wp_get_attachment_link( $imageatt->ID, 'full', true );
				echo '</li>


		<?php } } } ?>

Explanation :

- Here is Query to showing all of attachment image on wordpress post

$imageattach = get_posts( array(
			'post_type' => 'attachment',
			'posts_per_page' => -1,
			'post_parent' => $post->ID,
			'exclude'     => get_post_thumbnail_id()
		) );

2. Include these code below to the single.php file in your theme

<?php include('gallery-show.php'); ?>

3. Add this css script to beautify the look{text-align:center;}{font-size:11px;line-height:16px;overflow:hidden;width:134px;min-height:100px;float:left;}
.single-gallery{margin:0px 6px 6px 2px;}
.gallery-items img{border:1px solid #ccc;border-radius:4px;padding:2px;width:95% !important;height:80px !important;}
.gallery-items img:hover{box-shadow:0px 0px 3px #111;}

4. To run these script working properly, try use new post and then go to "add media", upload your images and dont include in the post (just upload from media in the post), because the picture gallery will show automatically into your wordpress post.

How to Show Picture Gallery Automatically in WordPress Post

Thus article about How to Show Picture Gallery Automatically in WordPress Post, hope useful.

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

%d bloggers like this: