Move gallery shortcode into separate file

This commit is contained in:
Ben Word
2013-06-23 12:19:49 -05:00
parent 5b52ddad22
commit 893244bbd3
3 changed files with 101 additions and 100 deletions

View File

@@ -10,6 +10,7 @@ require_once locate_template('/lib/config.php'); // Configuration
require_once locate_template('/lib/activation.php'); // Theme activation
require_once locate_template('/lib/cleanup.php'); // Cleanup
require_once locate_template('/lib/nav.php'); // Custom nav modifications
require_once locate_template('/lib/gallery.php'); // Custom [gallery] modifications
require_once locate_template('/lib/comments.php'); // Custom comments modifications
require_once locate_template('/lib/rewrites.php'); // URL rewriting for assets
require_once locate_template('/lib/relative-urls.php'); // Root relative URLs

View File

@@ -186,106 +186,6 @@ function roots_caption($output, $attr, $content) {
}
add_filter('img_caption_shortcode', 'roots_caption', 10, 3);
/**
* Clean up gallery_shortcode()
*
* Re-create the [gallery] shortcode and use thumbnails styling from Bootstrap
*
* @link http://twitter.github.com/bootstrap/components.html#thumbnails
*/
function roots_gallery($attr) {
$post = get_post();
static $instance = 0;
$instance++;
if (!empty($attr['ids'])) {
if (empty($attr['orderby'])) {
$attr['orderby'] = 'post__in';
}
$attr['include'] = $attr['ids'];
}
$output = apply_filters('post_gallery', '', $attr);
if ($output != '') {
return $output;
}
if (isset($attr['orderby'])) {
$attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
if (!$attr['orderby']) {
unset($attr['orderby']);
}
}
extract(shortcode_atts(array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post->ID,
'itemtag' => '',
'icontag' => '',
'captiontag' => '',
'columns' => 3,
'size' => 'thumbnail',
'include' => '',
'exclude' => '',
'link' => 'file'
), $attr));
$id = intval($id);
if ($order === 'RAND') {
$orderby = 'none';
}
if (!empty($include)) {
$_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
$attachments = array();
foreach ($_attachments as $key => $val) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif (!empty($exclude)) {
$attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
} else {
$attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
}
if (empty($attachments)) {
return '';
}
if (is_feed()) {
$output = "\n";
foreach ($attachments as $att_id => $attachment) {
$output .= wp_get_attachment_link($att_id, $size, true) . "\n";
}
return $output;
}
$output = '<ul class="thumbnails gallery">';
$i = 0;
foreach ($attachments as $id => $attachment) {
$image = ('file' == $link) ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
$output .= '<li>' . $image;
if (trim($attachment->post_excerpt)) {
$output .= '<div class="caption hidden">' . wptexturize($attachment->post_excerpt) . '</div>';
}
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
if (current_theme_supports('bootstrap-gallery')) {
remove_shortcode('gallery');
add_shortcode('gallery', 'roots_gallery');
}
/**
* Remove unnecessary dashboard widgets
*

100
lib/gallery.php Normal file
View File

@@ -0,0 +1,100 @@
<?php
/**
* Clean up gallery_shortcode()
*
* Re-create the [gallery] shortcode and use thumbnails styling from Bootstrap
*
* @link http://twitter.github.com/bootstrap/components.html#thumbnails
*/
function roots_gallery($attr) {
$post = get_post();
static $instance = 0;
$instance++;
if (!empty($attr['ids'])) {
if (empty($attr['orderby'])) {
$attr['orderby'] = 'post__in';
}
$attr['include'] = $attr['ids'];
}
$output = apply_filters('post_gallery', '', $attr);
if ($output != '') {
return $output;
}
if (isset($attr['orderby'])) {
$attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
if (!$attr['orderby']) {
unset($attr['orderby']);
}
}
extract(shortcode_atts(array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post->ID,
'itemtag' => '',
'icontag' => '',
'captiontag' => '',
'columns' => 3,
'size' => 'thumbnail',
'include' => '',
'exclude' => '',
'link' => 'file'
), $attr));
$id = intval($id);
if ($order === 'RAND') {
$orderby = 'none';
}
if (!empty($include)) {
$_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
$attachments = array();
foreach ($_attachments as $key => $val) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif (!empty($exclude)) {
$attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
} else {
$attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
}
if (empty($attachments)) {
return '';
}
if (is_feed()) {
$output = "\n";
foreach ($attachments as $att_id => $attachment) {
$output .= wp_get_attachment_link($att_id, $size, true) . "\n";
}
return $output;
}
$output = '<ul class="thumbnails gallery">';
$i = 0;
foreach ($attachments as $id => $attachment) {
$image = ('file' == $link) ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
$output .= '<li>' . $image;
if (trim($attachment->post_excerpt)) {
$output .= '<div class="caption hidden">' . wptexturize($attachment->post_excerpt) . '</div>';
}
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
if (current_theme_supports('bootstrap-gallery')) {
remove_shortcode('gallery');
add_shortcode('gallery', 'roots_gallery');
}