// No need to check that there is a minimum of 2 posts, thanks to dropdown in Settings $posts_number = $dfcg_options['posts-number']; /* Get the Selected Category/Term */ // No need to check Category existence, or whether it has Posts, // thanks to use of wp_dropdown_categories in Settings // With One Category Method, this is the cat ID $term_selected = $dfcg_options['cat-display']; /* Get the URL to the default "Category" images folder from Settings */ $def_img_folder_url = $dfcg_options['defimgonecat']; /* The query */ $query = 'cat=' . $term_selected . '&showposts=' . $posts_number; } if( $dfcg_options['populate-method'] == 'custom-post' ) { /* Get the Custom Post Type */ $post_type = $dfcg_options['custom-post-type']; /* Get the number of Posts to display */ // No need to check that there is a minimum of 2 posts, thanks to dropdown in Settings $posts_number = $dfcg_options['custom-post-type-number']; /* Get the Selected Category/Term */ // In format "taxonomy_name=term_Name" eg ade_products=Guitars $term_selected = $dfcg_options['custom-post-type-tax']; /* Get the URL to the default "Category" images folder from Settings */ $def_img_folder_url = $dfcg_options['defimgcustompost']; /* The query */ $query = 'post_type=' . $post_type . '&' . $term_selected . '&showposts=' . $posts_number; } // Added 3.1: Strip domain name from URL, replace with ABSPATH. Default folder can now be anywhere $def_img_folder_path = str_replace( get_bloginfo('url'), ABSPATH, $def_img_folder_url ); // Set a variable for the category default image using the cat ID number for the image name if( $term_selected !== '' ) { $def_img_name = $term_selected .'.jpg'; } else { $def_img_name = 'all.jpg'; } // Absolute path to default image, needed for file_exists() check $def_img_path = $def_img_folder_path . $def_img_name; /* Do the WP_Query */ $recent = new WP_Query( $query ); // Do we have any posts? if ( $recent->have_posts() ) { // Set a counter to find out how many Posts are found in the WP_Query // Also used to add an image # in the markup page source $counter = 0; $counter2 = 0; // Start the gallery markup $output = "\n" . '
'; $output .= "\n\t" . ''; $output .= "\n\t" . '
'; $output .= "\n\t\t" . '
'; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t\t" . ''; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t\t\t" . '

'; $output .= "\n\t\t\t\t" . '

'; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t\t\t" . '
'; $output .= "\n\t\t\t\t\t" . '
'; $output .= "\n\t\t\t\t\t\t" . '
'; $output .= "\n\t\t\t\t\t" . '
'; $output .= "\n\t\t\t\t\t" . '
'; $output .= "\n\t\t\t\t" . '
'; $output .= "\n\t\t\t\t" . '' . stripslashes($dfcg_options['textShowCarousel']) . ''; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t" . '
'; $output .= "\n\t" . '
'; $output .= "\n" . '
' . "\n\n"; if( $posts_number - $counter !== 0 ) { $output .= "\n\n" . $dfcg_errmsgs['7']; } // Print out stats if( $dfcg_options['errors'] == "true" ) { $post_found = $counter - $counter2; $output .= "\n" . ''; $output .= "\n" . ''; $output .= "\n" . ''; $output .= "\n\n" . ''."\n\n"; } } else { /* Oops! The WP_Query couldn't find any Posts */ // Theoretically this can never happen unless there is a WP problem $output = "\n" . $dfcg_errmsgs['8']; } // Output the Gallery echo $output; } /** * This function builds the gallery from ID Method options * * NOTE: This function was renamed in v3.3 (formally dfcg_jq_pages_method_gallery() ) * * @uses dfcg_postmeta_info() Builds array of postmeta key names (see dfcg-gallery-core.php) * @uses dfcg_errors_output() Gets all Error Messages, if errors are on (see dfcg-gallery-errors.php) * @uses dfcg_baseimgurl() Determines whether FULL or Partial URL applies (see dfcg-gallery-core.php) * @uses dfcg_query_list() Builds array of cat/off pairs for WP_Query (see dfcg-gallery-core.php) * @uses dfcg_the_content_limit() Creates Auto description (see dfcg-gallery-content-limit.php) * @uses dfcg_grab_post_image() Gets the first image attachment from the Post (see dfcg-gallery-core.php) * * @var array $postmeta Array of postmeta keys, eg _dfcg-image, etc. Output of dfcg_postmeta_info() * @var array $dfcg_errmsgs Array of error messages. Output of dfcg_errors_output() * @var string $baseimgurl Base URL for images. Empty if FULL URL. Output of dfcg_baseurl() * @var string $ids_selected DCG option: comma separated list of Page/Post IDs * @var string $ids_selected_count No. of Page/Post IDs specified in DCG options * @var array $ids_found $wpdb query object * @var string $ids_found_count Number of Pages in $wpdb query object * @var string $counter Incremented variable to add image # in HTML comments markup * @var string $slide_text Slide Pane description text * @var string $link Image link URL, either to Post/Page or External * @var string $auto_image First image attachment in the Post, as URL * @var string $image_src SRC of gallery image * @var string $image_err Error message, if relevant * @var string $thumb Stores output of get_the_post_thumbnail() function, for accessing Post Thumbnails/Featured Image * @var string $thumb_html Stores HTML of thumbnail IMG * * @global array $dfcg_options Plugin options array from db * @global array $wpdb WP $wpdb database object * * @since 3.3 */ function dfcg_jq_id_method_gallery() { global $dfcg_options, $dfcg_postmeta_upgrade; $postmeta = dfcg_postmeta_info(); // Build array of error messages (NULL if Errors are off) $dfcg_errmsgs = NULL; if( function_exists( 'dfcg_errors_output' ) ) { $dfcg_errmsgs = dfcg_errors_output(); } // Set $baseimgurl variable for image URL $baseimgurl = dfcg_baseimgurl(); /* Get the comma separated list of Page ID's */ $ids_selected = trim($dfcg_options['ids-selected']); if( !empty($ids_selected) ) { /* Get rid of the final comma so that the variable is ready for use in SQL query */ // If last character in string is a comma if( substr( $ids_selected, -1) == ',' ) { // Remove the final comma in the list $ids_selected = substr( $ids_selected, 0, substr( $ids_selected, -1)-1 ); } /* Turn the list into an array */ $ids_selected = explode(",", $ids_selected); /* Store how many IDs were in list */ $ids_selected_count = count($ids_selected); /* If only one Page ID has been specified in Settings: print error messages and exit */ if( $ids_selected_count < 2 ) { $output = $dfcg_errmsgs['1'] . "\n"; echo $output; return; } } else { /* There are no Page IDs in Settings: print error messages and exit */ $output = $dfcg_errmsgs['2'] . "\n"; echo $output; return; } /* Instantiate the $wpdb object */ global $wpdb; if( $dfcg_options['id-sort-control'] == 'true' ) { /* User defined sort order for Pages */ $sort = esc_attr('_dfcg-sort'); /* Do the query - with thanks to Austin Matzko for sprintf help */ $ids_found = $wpdb->get_results( sprintf("SELECT ID,post_title,post_content FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '%s' WHERE $wpdb->posts.ID IN( %s ) ORDER BY $wpdb->postmeta.meta_value ASC", $sort, implode(',', array_map( 'intval', $ids_selected )) ) ); } else { /* Do the query - with thanks to Austin Matzko for sprintf help */ /* Note: simplified query without custom sort ordering */ $ids_found = $wpdb->get_results( sprintf("SELECT ID,post_title,post_content FROM $wpdb->posts WHERE $wpdb->posts.ID IN( %s )", implode(',', array_map( 'intval', $ids_selected ) ) ) ); } /* If we have results from the query */ if( $ids_found ) { // Validation: Check how many Pages the query found // The results if this are printed to Page Source further down $ids_found_count = count($ids_found); // If less than 2, print error messages and exit function if( $ids_found_count < 2 ) { $output .= "\n" . $dfcg_errmsgs['9']; if( $dfcg_options['errors'] == "true" ) { $output .= "\n" . ''; $output .= "\n" . ''; } echo $output; return; } // Set a counter to add an image # in the markup page source $counter = 0; // Start the gallery markup $output = "\n" . '
'; $output .= "\n\t" . ''; $output .= "\n\t" . '
'; $output .= "\n\t\t" . '
'; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t\t" . ''; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t\t\t" . '

'; $output .= "\n\t\t\t\t" . '

'; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t\t\t" . '
'; $output .= "\n\t\t\t\t\t" . '
'; $output .= "\n\t\t\t\t\t\t" . '
'; $output .= "\n\t\t\t\t\t" . '
'; $output .= "\n\t\t\t\t\t" . '
'; $output .= "\n\t\t\t\t" . '
'; $output .= "\n\t\t\t\t" . '' . stripslashes($dfcg_options['textShowCarousel']) . ''; $output .= "\n\t\t\t" . '
'; $output .= "\n\t\t" . '
'; $output .= "\n\t" . '
'; $output .= "\n" . '
' . "\n\n"; /* Compare $pages_selected_count with the db query object $pages_found_count to check that the number of gallery images is the same. If it's not the same, then one or more of the selected Page IDs are not valid Pages */ if( $ids_found_count !== $ids_selected_count) { $output .= "\n" . $dfcg_errmsgs['5']; if( $dfcg_options['errors'] == "true" ) { $output .= "\n" . ''; $output .= "\n" . ''; $output .= "\n" . ''."\n\n"; } } } else { /* Oops! Either none of the Page IDs are valid or the db query failed in some way */ $output = "\n" . $dfcg_errmsgs['6']; } // Output the Gallery echo $output; }