How To Add Gallery Post Format In WordPress Theme?
October 15th, 2016 | by Ravi Chahar || Leave a comment |
As shown in the another post, there are many types of post formats in WordPress. There is a post format called “Gallery“.
Do you know how to add gallery post format in WordPress theme? You can add the theme support option for the gallery post format but how would you show it as a post?
In this tutorial, you will learn about creating a gallery post and how to add gallery post format in WordPress. I hope you know how to create a gallery in WordPress from the media library.
Add Gallery Post Format In WordPress Theme By Creating A New File.
If you are aware of the WordPress theme file structure then it won’t be hard for you to add a new file in the theme folder.
Just create a new file named “content-gallery.php“.
This file will handle the output of the gallery post. When you add the images and publish it, it will not display as the simple post. All the images will be showing to your blog page along with your standard post.
In this file, you have to add the code which would handle the output of the gallery post format.
Let me provide you an example.
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</article>
When you publish a post choosing the post format as Gallery then the images will be published as a Gallery post. You will see all the images with your chosen columns.
Your task to add gallery post format in WordPress theme has completed, but the designing is still on you.
You can use the class given above and target the images of the gallery to give it an elegant look.
background-color: #222;
color: #FFF;
padding: 20px;
border-bottom: none;
}
border: none!important;
}
text-align: center;
text-size: 18px;
}
The above code would add the background to the post and the border of the images would be removed.
NOTE:- Border comes by default, to remove this, you have to use the “important” value if the simple value doesn’t work.
Let me show you the result.
You have successfully added the gallery post format in your WordPress theme. Now you can add as many gallery posts you want.
Can You Now try To Add Gallery Post Format In WordPress?
To accomplish the task of adding all the post formats, you must have the proper knowledge of PHP and WordPress functions.
The above-mentioned code would add gallery post format in WordPress theme but to display it properly, you have to add the post format function in the loop.