function get_easy_nivo_slider_for_current_post($parms = NULL) { // Start an output buffer to capture any output ob_start(); $options = get_option('easy_nivo_slider_options'); sns_debug('get_easy_nivo_slider_for_current_post', $parms); if (!$parms) { return ob_get_clean(); } $qry = array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'nopaging' => true); //echo 'THE ID : '.get_the_ID().'<br>'; // Fetch the posts with the passed query sns_debug('WP_Query', $qry); $images = get_children($qry); if ($images) { // Track the number of sliders on a page so each one has a unique ID $parms = sns_set_slider_id($parms); // Initialize the parms so everything has a value $parms = sns_set_empty_parms_to_defaults($parms); // Limit the number of images in slider $number_of_images = 0; // Perform the loop and build the slider //if (!$options['debug']) echo '<div class="easy-nivo-slider easy-nivo-slider-' . $parms['size'] . ' ' . $parms['class'] . '" id="slider-' . $parms['ID'] . '">'; // Initialize some loop variabls $thumbnail = ''; foreach ($images as $id => $image) { if ('true' == $parms['linking']) { echo '<a href="' . wp_get_attachment_url($id) . '" title="' . get_the_title($id) . '">'; } $arr_image = wp_get_attachment_image_src($id, $parms['width'] . 'x' . $parms['height']); // For thumbnail navigation, generate a thumnail and build the image code manually if ('true' == $parms['controls_thumbs']) { $arr_thumb = wp_get_attachment_image_src($id, '60x60'); $thumbnail = ' rel="' . $arr_thumb[0] . '"'; } echo '<img src="' . $arr_image[0] . '" ' . ('true' == $parms['caption'] ? ' title="' . get_the_title($id) . '"' : '') . $thumbnail . '/>'; // Without thumbnail navigation, we can just print the image //} else { // echo wp_get_attachment_image( $id, $parms['width'].'x'.$parms['height'] ); //} if ('true' == $parms['linking']) { echo '</a>'; } $number_of_images++; if ($number_of_images >= $parms['number']) { break; } } // foreach // If the slider has any pictures, add the javascript to start it if ($number_of_images > 0) { sns_print_script_for_slider($parms); } //if (!$options['debug']) echo '</div>'; } if (0 == $number_of_images) { echo '<p>No images found.</p>'; } //return the current buffer and clear it return ob_get_clean(); }
function get_easy_nivo_slider_for_nextgen($parms = NULL) { global $wpdb; // Start an output buffer to capture any output ob_start(); sns_debug('get_easy_nivo_slider_for_nextgen', $parms); if (!$parms) { return ob_get_clean(); } $sql_where = ' WHERE exclude = 0'; if ('' != $parms['gallery']) { $sql_where .= ' AND galleryid=' . $parms['gallery']; } $results = $wpdb->get_results("SELECT * FROM {$wpdb->nggpictures}" . $sql_where); // ." ORDER BY ".$sql_order.$sql_limit $num_results = 0; if (is_array($results)) { $num_results = count($results); } $output = ''; if ($num_results > 0) { $image_alt = null; $image_description = null; // Track the number of sliders on a page so each one has a unique ID $parms = sns_set_slider_id($parms); // Initialize the parms so everything has a value $parms = sns_set_empty_parms_to_defaults($parms); // Limit the number of images in slider $number_of_images = 0; // Set up image size parameters for later $size = ' width="' . $parms['width'] . '" height="' . $parms['height'] . '" '; // Start the slider DIV echo '<div class="easy-nivo-slider easy-nivo-slider-' . $parms['size'] . ' ' . $parms['class'] . '" id="slider-' . $parms['ID'] . '">'; // Loop for each image in the gallery foreach ($results as $result) { // Fetch gallery information for each image $gallery = $wpdb->get_row("SELECT * FROM {$wpdb->nggallery} WHERE gid = '" . $result->galleryid . "'"); // Copy gallery fields into the image array foreach ($gallery as $key => $value) { $result->{$key} = $value; } // Instantiate a nextGen image from the image array $image = new nggImage($result); $image_alt = trim($image->alttext); $image_description = trim($image->description); // check that alt is url with a easy validation $use_url = false; if ('' != $image_alt && (substr($image_alt, 0, 1) == '/' || substr($image_alt, 0, 4) == 'http' || substr($image_alt, 0, 3) == 'ftp')) { $use_url = true; // if alt isn't a url make it the alt text to backwards support nextgen galleries } elseif ('' != $image_alt) { $image_description = $image_alt; } /* Retrieve the image description if ('' != $image_description) { $image_description = "alt=\"" . esc_attr($image_description) . "\" ";} else { $image_description = ''; } */ // Start the link if ('true' == $parms['linking'] && '' != $use_url) { echo "<a href=\"" . esc_attr($image_alt) . "\">"; } // Output the image // Note that this outputs the original nextgen image, not the resized one. need to figure out how // to get that one, if it exists echo '<img src="' . $image->imageURL . '" ' . $image_description . $size . ' border="0" />'; // Finish the link if ('true' == $parms['linking'] && '' != $use_url) { echo '</a>'; } // Check to see if we've reached our maxiumum image count $number_of_images++; if ($number_of_images >= $parms['number']) { break; } } echo '</div>'; // If the slider has any pictures, add the javascript to start it if ($number_of_images > 0) { sns_print_script_for_slider($parms); } } if (0 == $number_of_images) { echo '<p>No images found.</p>'; } //return the current buffer and clear it return ob_get_clean(); }
function get_easy_nivo_slider_for_featured_images($parms = NULL) { // Start an output buffer to capture any output ob_start(); sns_debug('get_easy_nivo_slider_for_featured_images', $parms); if (!$parms) { return ob_get_clean(); } $qry = array('nopaging' => true, 'posts_per_page' => -1, 'post_type' => $parms['post_type'], 'post_status' => 'publish'); // Set a default post_type if (NULL == $qry['post_type']) { $qry['post_type'] = 'post'; } // WP_Query uses category_name if (NULL != $parms['category']) { $qry['category_name'] = $parms['category']; } // Set the taxonomy and term for WP_Query if (NULL != $parms['taxonomy'] && NULL != $parms['term']) { $qry[$taxonomy] = $parms['term']; } // Fetch the posts with the passed query sns_debug('WP_Query', $qry); $r = new WP_Query($qry); if ($r->have_posts()) { // Track the number of sliders on a page so each one has a unique ID $parms = sns_set_slider_id($parms); // Initialize the parms so everything has a value $parms = sns_set_empty_parms_to_defaults($parms); // Limit the number of images in slider $number_of_images = 0; // Perform the loop and build the slider echo '<div class="easy-nivo-slider easy-nivo-slider-' . $parms['size'] . ' ' . $parms['class'] . '" id="slider-' . $parms['ID'] . '">'; // Initialize some loop variabls $thumbnail = ''; while ($r->have_posts()) { $r->the_post(); if (has_post_thumbnail()) { if ('true' == $parms['linking']) { echo '<a href="' . get_permalink() . '" title="' . get_the_title() . '">'; } $arr_image = wp_get_attachment_image_src(get_post_thumbnail_id(), $parms['width'] . 'x' . $parms['height']); // For thumbnail navigation, generate a thumnail and build the image code manually if ('true' == $parms['controls_thumbs']) { $arr_thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), '60x60'); $thumbnail = ' rel="' . $arr_thumb[0] . '"'; } echo '<img src="' . $arr_image[0] . '" ' . ('true' == $parms['caption'] ? ' title="' . get_the_title(get_post_thumbnail_id()) . '"' : '') . $thumbnail . '/>'; if ('true' == $parms['linking']) { echo '</a>'; } $number_of_images++; if ($number_of_images >= $parms['number']) { break; } } } echo '</div>'; // Reset the global $the_post because we stomped on it wp_reset_postdata(); // If the slider has any pictures, add the javascript to start it if ($number_of_images > 0) { sns_print_script_for_slider($parms); } } // if ($r->have_posts()) if (0 == $number_of_images) { echo '<p>No images found.</p>'; } //return the current buffer and clear it return ob_get_clean(); }