defsounds

http://revisedagain.com/wp-content/themes/r

Customizing WordPress’s Native Gallery

Posted on March 30th, 2011 Customizing WordPress’s Native Gallery

There are a lot of fancy wordpress plugins out there for photo galleries. But what if you just want to use the native gallery with a bit of customization? I made the mistake of assuming this would be a pretty quick and basic task–boy was I wrong–wronger than a tsunami joke two weeks ago (which I totally did..go on..ask me what it was).

Here are the files you’ll need to edit:
Attachment.php/Attachment-loop.php [From your theme]
Functions.php [From your theme]
Media.php [wp-includes folder]

//function to get next or previous keys in an array
function array_navigate($array, $key){
$keys = array_keys($array);
$index = array_flip($keys);
$return = array();
$return['prev'] = (isset($keys[$index[$key]-1])) ? $keys[$index[$key]-1] : end($keys);
$return['next'] = (isset($keys[$index[$key]+1])) ? $keys[$index[$key]+1] : current($keys);
return $return;
}

//previous attachment link function
function prev_att_link(){
global $post;
$post = get_post($post);
//get the attachments which share the same post parent
$images =& get_children(‘post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent=’.$post->post_parent);
if($images){
//get the id of the previous attachment
$ppid_arr = array_navigate($images, $post->ID);
$ppid = $ppid_arr['prev'];
foreach($images as $key => $value){
if($key == $ppid){
$output = ‘‘;
}
}
return $output;
} else {
//there is no previous link
return false;
}
}

//next attachment link function
function next_att_link(){
global $post;
$post = get_post($post);
//get the attachments which share the same post parent
$images =& get_children(‘post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent=’.$post->post_parent);
if($images){
//get the id of the next attachment
$ppid_arr = array_navigate($images, $post->ID);
$ppid = $ppid_arr['next'];
foreach($images as $key => $value){
if($key == $ppid){
$output = ‘‘;
}
}
return $output;
} else {
//there is no next link
return false;
}
}

//back to gallery link function
function back_to_gal_link(){
global $post;
$post = get_post($post);
$post_par = get_post($post->post_parent);
$slug = get_permalink($post_par->ID);
return ‘« Back to gallery‘;
}

Leave a comment