Skip to content

Instantly share code, notes, and snippets.

@axyz
Last active August 29, 2015 14:16
Show Gist options
  • Save axyz/ae73382d03acd4037095 to your computer and use it in GitHub Desktop.
Save axyz/ae73382d03acd4037095 to your computer and use it in GitHub Desktop.
axyz-post-gallery
<?php
/*
Plugin Name: WP Post Gallery
Version: 0.1
Author: Andrea Moretti (@axyz)
Author URI: http://github.com/axyz
License: GPL2
*/
function post_gallery_shortcode($atts) {
// Attributes
extract(shortcode_atts(
array(
'id' => '',
'class' => ''
), $atts)
);
// Code
if (isset($id)) {
$class = (isset($class))? $class : "";
$gallery = get_post_gallery_images($id);
$element = "<div id='axyz-post-gallery-$id' class='axyz-post-gallery $class'>";
foreach ($gallery as $img) {
$element .= "<div class='axyz-post-gallery-item'><img src='$img'></div>";
}
$element .= "</div>";
return $element;
}
}
add_shortcode('post-gallery', 'post_gallery_shortcode');
<?php
add_action('wp_footer', 'gfwsp_footer_scripts');
if (!function_exists('gfwsp_footer_scripts')) {
function gfwsp_footer_scripts()
{
wp_enqueue_script('gfwsp-masonry',
get_stylesheet_directory_uri() . '/node_modules/masonry-layout/dist/masonry.pkgd.min.js',
array('jquery'));
wp_enqueue_script('gfwsp-init',
get_stylesheet_directory_uri() . '/init.js',
array('gfwsp-masonry'));
}
}
(function($, Masonry, undefined) {
"use strict";
$(function () {
var msnry = new Masonry('.axyz-post-gallery', {
columnWidth: 1,
itemSelector: '.axyz-post-gallery-item',
transitionDuration: 0
});
});
})(jQuery, Masonry)
/**********************
* MASONRY GALLERY *
*********************/
.masonry .axyz-post-gallery-item {
width: 19%;
margin-left: 10px;
margin-bottom: 10px;
webkit-box-shadow: 0 1px 3px rgba(34, 25, 25, 0.7);
moz-box-shadow: 0 1px 3px rgba(34, 25, 25, 0.7);
box-shadow: 0 1px 3px rgba(34, 25, 25, 0.7);
line-height: 0px;
}
.masonry.axyz-post-gallery {
margin: 0 0 0 25px;
padding: 0;
}
@media (min-width:1680px) and (max-width:1920) {
.masonry.axyz-post-gallery {
margin: 0 0 0 20px;
}
}
@media (min-width:1460px) and (max-width:1680px) {
.masonry.axyz-post-gallery {
margin: 0 0 0 15px;
}
}
@media (min-width:980px) and (max-width:1460px) {
.masonry .axyz-post-gallery-item {
width: 24%;
}
.msaonry.axyz-post-gallery {
margin: 0 0 0 0px;
}
}
@media (min-width:979px) and (max-width:1200px) {
.masonry.axyz-post-gallery {
margin: 0 0 0 -2px;
}
}
@media (min-width:768px) and (max-width:979px) {
.masonry .axyz-post-gallery-item {
width: 32%;
}
.masonry.axyz-post-gallery {
margin: 0 0 0 -5px;
}
}
@media handheld,only screen and (max-width:767px) {
.masonry .axyz-post-gallery-item {
width: 46%;
}
.masonry.axyz-post-gallery {
margin: 0 0 0 13px;
}
}
@media handheld,only screen and (max-width:480px) {
.masonry .axyz-post-gallery-item {
width: 100%;
}
.msaonry.axyz-post-gallery {
margin: 0 0 0 -10px;
}
}
/***********************
* END MASONRY GALLERY *
**********************/
/****************
* GRID GALLERY *
***************/
.grid .axyz-post-gallery {
margin: 35px 0 0 0;
padding: 0;
list-style: none;
position: relative;
width: 100%;
}
.grid .axyz-post-gallery-item {
position: relative;
float: left;
overflow: hidden;
width: 25%; /* Fallback */
width: -webkit-calc(100% / 4);
width: calc(100% / 4);
}
.grid .axyz-post-gallery-item img {
display: block;
width: 100%;
cursor: pointer;
}
.grid .axyz-post-gallery-item img {
max-width: 100%;
}
/* Flexbox is used for centering the heading */
.grid .axyz-post-gallery-item div {
position: absolute;
left: 20px;
top: 20px;
right: 20px;
bottom: 20px;
background: rgba(71,163,218,0.2);
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: flex;
-webkit-align-items: center;
-moz-align-items: center;
-ms-align-items: center;
align-items: center;
text-align: center;
opacity: 0;
}
@media screen and (max-width: 767px) {
.grid .axyz-post-gallery-item {
width: 50%; /* Fallback */
width: -webkit-calc(100% / 2);
width: calc(100% / 2);
}
}
@media screen and (max-width: 480px) {
.grid .axyz-post-gallery-item {
width: 100%;
}
}
/********************
* END GRID GALLERY *
*******************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment