Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created June 13, 2013 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/5220a29adf43bbaa6c5f to your computer and use it in GitHub Desktop.
Save billerickson/5220a29adf43bbaa6c5f to your computer and use it in GitHub Desktop.
Remember which gallery you came from
<?php
/**
* Gallery Image
*
* @package BE_Genesis_Child
* @since 1.0.0
* @link https://github.com/billerickson/BE-Genesis-Child
* @author Bill Erickson <bill@billerickson.net>
* @copyright Copyright (c) 2011, Bill Erickson
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*
*/
// Remove Things
add_filter( 'prepend_attachment', '__return_false' );
remove_action( 'genesis_after_post', 'genesis_get_comments_template' );
remove_action( 'genesis_post_title', 'genesis_do_post_title' );
remove_action( 'genesis_before_post_content', 'genesis_post_info' );
/**
* Attachment Content
*
*/
function be_attachment_content() {
global $post;
echo '<p class="attachment-navigation">';
previous_image_link( false, '&laquo; Previous' );
$all = isset( $_GET['dcf_gallery'] ) ? get_permalink( esc_attr( $_GET['dcf_gallery'] ) ) : get_permalink( $post->post_parent );
echo ' | <a href="' . $all . '">All Photos</a> | ';
next_image_link( false, 'Next &raquo;' );
echo '</p>';
$image = wp_get_attachment_image_src( get_the_ID(), 'large' );
echo '<p class="attachment"><img src="' . $image[0] . '" /></p>';
}
add_action( 'genesis_post_content', 'be_attachment_content', 5 );
/**
* Add Gallery Arg to Adjacent Link
*
*/
function be_previous_gallery_link( $output, $id, $size, $permalink, $icon, $text ) {
$id = intval( $id );
$_post = get_post( $id );
if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) )
return __( 'Missing Attachment' );
if ( $permalink )
$url = get_attachment_link( $_post->ID );
if( isset( $_GET['dcf_gallery'] ) )
$url = add_query_arg( 'dcf_gallery', esc_attr( $_GET['dcf_gallery'] ), $url );
$post_title = esc_attr( $_post->post_title );
if ( $text )
$link_text = $text;
elseif ( $size && 'none' != $size )
$link_text = wp_get_attachment_image( $id, $size, $icon );
else
$link_text = '';
if ( trim( $link_text ) == '' )
$link_text = $_post->post_title;
return '<a href="' . $url . '" title="' . $post_title . '">' . $link_text . '</a>';
}
add_filter( 'wp_get_attachment_link', 'be_previous_gallery_link', 10, 6 );
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment