Created
October 4, 2012 16:40
-
-
Save billrobbins/3834840 to your computer and use it in GitHub Desktop.
Gallery Portfolio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Portfolio function | |
* | |
* This file adds the functions allowing | |
* users to select which images are | |
* included in the portfolio page template | |
* | |
* @package WordPress | |
* @subpackage organizedthemes | |
* @since Photo 1.0 | |
* | |
* | |
* @param $form_fields array, fields to include in attachment form | |
* @param $post object, attachment record in database | |
* @return $form_fields, modified form fields | |
*/ | |
function be_attachment_field_rotator( $form_fields, $post ) { | |
// Set up options | |
$options = array( '1' => 'Yes', '0' => 'No' ); | |
// Get currently selected value | |
$selected = get_post_meta( $post->ID, 'be_rotator_include', true ); | |
// If no selected value, default to 'No' | |
if( !isset( $selected ) ) | |
$selected = '0'; | |
// Display each option | |
foreach ( $options as $value => $label ) { | |
$checked = ''; | |
$css_id = 'rotator-include-option-' . $value; | |
if ( $selected == $value ) { | |
$checked = " checked='checked'"; | |
} | |
$html = "<div class='rotator-include-option'><input type='radio' name='attachments[$post->ID][be-rotator-include]' id='{$css_id}' value='{$value}'$checked />"; | |
$html .= "<label for='{$css_id}'>$label</label>"; | |
$html .= '</div>'; | |
$out[] = $html; | |
} | |
// Construct the form field | |
$form_fields['be-include-rotator'] = array( | |
'label' => 'Include on portfolio page', | |
'input' => 'html', | |
'html' => join("\n", $out), | |
); | |
// Return all form fields | |
return $form_fields; | |
} | |
add_filter( 'attachment_fields_to_edit', 'be_attachment_field_rotator', 10, 2 ); | |
/** | |
* Save value of "Include in Rotator" selection in media uploader | |
* | |
* @param $post array, the post data for database | |
* @param $attachment array, attachment fields from $_POST form | |
* @return $post array, modified post data | |
*/ | |
function be_attachment_field_rotator_save( $post, $attachment ) { | |
if( isset( $attachment['be-rotator-include'] ) ) | |
update_post_meta( $post['ID'], 'be_rotator_include', $attachment['be-rotator-include'] ); | |
return $post; | |
} | |
add_filter( 'attachment_fields_to_save', 'be_attachment_field_rotator_save', 10, 2 ); | |
// adds an action to display the slider in the single and page templates | |
add_action( 'organizedthemes_gallery_format', 'organizedthemes_gallery_format_create' ); | |
function organizedthemes_gallery_format_create( ) { ?> | |
<?php | |
$args = array( | |
'post_type' => 'attachment', | |
'post_mime_type' => 'image', | |
'post_status' => 'inherit', | |
'post_parent' => $post->ID, | |
'posts_per_page' => '-1', | |
'order' => 'ASC', | |
'orderby' => 'menu_order', | |
'meta_query' => array( | |
array( | |
'key' => 'be_rotator_include', | |
'value' => '1' | |
) | |
) | |
); | |
$images = new WP_Query( $args ); | |
if( !$images->have_posts() ) | |
return; | |
while( $images->have_posts() ): $images->the_post(); global $post; | |
$parent_title = get_the_title($post->post_parent); | |
$image = wp_get_attachment_image_src( $post->ID, 'small-feature' ); | |
$image_full = wp_get_attachment_image_src( $post->ID, 'large' ); | |
$image_attributes = wp_get_attachment_image_src( $post->ID, 'small-feature' ); | |
$caption = get_the_excerpt( $post->ID, 'post_excerpt' ); | |
echo '<a class="lightbox" title="'.$caption.'" rel="portfolio" href="'; | |
echo $image_full[0] . '">'; | |
echo '<img class="shadow brick" src="'; | |
echo $image[0] . '" width="'.$image_attributes[1] .'" height="'.$image_attributes[2].'" />'; | |
echo '</a>'; | |
echo ' | |
'; | |
endwhile; wp_reset_query(); | |
?> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment