Search
Close this search box.

Creating a Photo Gallery in WordPress With No Plugins

[updated_on]
Share this post:

WordPress is one of the most popular publishing platforms in the world and users are looking for new features every day. Luckily, the platform allows you to do a lot of things, especially if you know a bit of coding. In this article, we will show you how to create a photo album gallery in WordPress without using a plugin. It is extremely useful for users who want to organize their photos in monthly albums, because it allows them to see all the posts that include photos from that month.

To create photo album galleries in WordPress, you need to make sure every photo has its own individual page, which will give you information about the photo and a URL. Usually, people simply use the NextGen Gallery plugin, but if you want to avoid using third parties, here is a tutorial for you.

What do we need?

We will try to create an Albums page, where users can see an archive with all the photo albums. Each album will have a distinguishing cover, and they will be organized by month. Once a user clicks on an album he will see a list of all the pictures inside the album and some background information. They can also click on a photo and go to the photo’s page.

How to create a photo album gallery in WordPress

To create a photo album gallery in WordPress we will use the platform’s functionalities.  Each monthly album will be considered a post, which will allow them to have their own page. The images will be considered attachments. To work on this you can simply use the default posts.

Creating the photo album gallery in WordPress

Before proceeding to the work, make sure you create a specific site plugin; a specific project plugin could work as well. To generate the code for your project you can use Custom Post Types and simply copy and paste the code into the site-specific plugin.

The next step is to register in WordPress new image sizes for the grid display:

add_image_size( 'album-grid', 225, 150, true );

Once you finish with the additional image sizes, you can also add some extra fields in the Media uploader. You will use them to add the name of the Photographer and the URL for each image. Continue and add some albums, just as new posts. You can start uploading the images in every album and choose a separate picture as the album cover. If you want to add background information, do it in the content area of your post.

When you finish with the albums you can start coding in order to display them. Simply create a template file and name it archive-albums.php. Paste the header, footer, sidebar, and any other display codes. Move ahead and create a post loop, where you can display all the attachments.

Here is what the code should look like:

  • post_type == 'albums' && $post->post_status == 'publish' ) { $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $post->ID, 'exclude' => get_post_thumbnail_id() ) ); if ( $attachments ) { foreach ( $attachments as $attachment ) { $class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type ); $title = wp_get_attachment_link( $attachment->ID, 'album-grid', true ); echo '
  • ' . $title . '
  • '; } } } ?>

    For style use a CSS code in the class .album-grid.

    .album-grid{width: 225px; height: 150px; float: left; list-style: none; list-style-type: none; margin: 0 18px 30px 0px;}

    Start creating a single-attachment template, so you can view each image separately. You can style it however you want.

    Create a single-albums.php file and add any design element you want.

    You are done. You have just created a monthly photo album gallery in WordPress without using a plugin. If you need any help, leave a comment and we will be back to you!

    Share this post:

    Leave a Comment

    Your email address will not be published. Required fields are marked *

    WPLearningLab