• Resolved eaferrari24

    (@eaferrari24)


    Trying to get the widget function of WP Photo Album Plus to show multiple (2) random images but I cant figure out how to get 2 different images to show. I have tried using independent variables but I have a feeling that I am forgetting something. :\

    Here is the original code from the wppa_widget.php file

    The bold lines are the ones I have attempted to duplicate, modify, etc

    <?php
    /* wppa_widget.php
    * Package: wp-photo-album-plus
    *
    * display the widget
    * Version 1.9.1
    */
    
    add_action('plugins_loaded', 'init_wppa_widget');
    
    function init_wppa_widget() {
    	register_sidebar_widget('Photo Album Widget', 'show_wppa_widget');
    }
    
    function show_wppa_widget($args) {
    	global $wpdb;
    	extract($args);
    
    	// get the title
    	$widget_title = get_option('wppa_widgettitle', __('Photo of the day', 'wppa'));
    
    	// get the photo  ($image)
    	switch (get_option('wppa_widget_method', '1')) {
    		case '1':	// Fixed photo
    			$id = get_option('wppa_widget_photo', '');
    			if ($id != '') {
    				$image = $wpdb->get_row($wpdb->prepare('SELECT * FROM <code>' . PHOTO_TABLE . '</code> WHERE <code>id</code> = %d LIMIT 0,1', $id), 'ARRAY_A');
    			}
    			break;
    		<strong>case '2':	// Random
    			$album = get_option('wppa_widget_album', '');
    			if ($album != '') {
    				$image = $wpdb->get_row($wpdb->prepare('SELECT * FROM <code>' . PHOTO_TABLE . '</code> WHERE <code>album</code> = %d ORDER BY RAND() LIMIT 0,1', $album), 'ARRAY_A');
    			}</strong>
    			break;
    		case '3':	// Last upload
    			$album = get_option('wppa_widget_album', '');
    			if ($album != '') {
    				$image = $wpdb->get_row($wpdb->prepare('SELECT * FROM <code>' . PHOTO_TABLE . '</code> WHERE <code>album</code> = %d ORDER BY <code>id</code> DESC LIMIT 0,1', $album), 'ARRAY_A');
    			}
    			break;
    		case '4':	// Change every
    			$album = get_option('wppa_widget_album', '');
    			if ($album != '') {
    				$u = date("U"); // Seconds since 1-1-1970
    				$u /= 3600;		//  hours since
    				$u = floor($u);
    				$u /= get_option('wppa_widget_period', '168');
    				$u = floor($u);
    				$p = wppa_get_photo_count($album);
    				if (!is_numeric($p) || $p < 1) $p = '1'; // make sure we dont get overflow in the next line
    				$idn = fmod($u, $p);
    				$photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM <code>' . PHOTO_TABLE . '</code> WHERE <code>album</code> = %d ' . wppa_get_photo_order($album), $album), 'ARRAY_A');
    				$i = 0;
    				foreach ($photos as $photo) {
    					if ($i == $idn) {	// found the idn'th out of p
    						$image = $photo;
    					}
    					$i++;
    				}
    			} else {
    				$image = '';
    			}
    			break;
    		case '5':	// Slideshow
    				$widget_content = __('Not implemented yet (5)');
    				$image = '';
    			break;
    		case '6':	// Scrollable
    				$widget_content = __('Not implemented yet (6)');
    				$image = '';
    			break;
    	}
    
    	// Make the HTML for current picture
    	$widget_content = '<div class="wppa-widget">';
    	if ($image) {
    		// make image url
    		$imgurl = get_bloginfo('wpurl') . '/wp-content/uploads/wppa/' . $image['id'] . '.' . $image['ext'];
    
    		// Find link page if any, if we find a title, there is a valid page to link to
    		$pid = get_option('wppa_widget_linkpage', '0');
    		$page_title = $wpdb->get_var("SELECT post_title FROM " . $wpdb->posts . " WHERE post_type = 'page' AND post_status = 'publish' AND ID=" . $pid);
    		<strong>if ($page_title) { 			// Yep, Linkpage found
    			$title = __('Link to', 'wppa') . ' ' . $page_title;
    			$widget_content .= '<a href="' . get_page_link($pid) . '">';
    		}
    		else {
    			$title = $widget_title;
    		}
    
    		$widget_content .= '<img src="' . $imgurl . '" style="width: ' . get_option('wppa_widget_width', '150') . 'px;" title="' . $title . '" alt="' . $title . '">';
    
    		if ($page_title) $widget_content .= '</a>';
    	}
    	else {	// No image
    		$widget_content .= __('Photo not found.');
    	}
    	$widget_content .= '</div>';</strong>
    	// Add subtitle, if any
    	switch (get_option('wppa_widget_subtitle', 'none'))
    	{
    		case 'none':
    			break;
    		case 'name':
    			if ($image && $image['name'] != '') {
    				$widget_content .= '<div class="wppa-widget-text">' . stripslashes($image['name']) . '</div>';
    			}
    			break;
    		case 'desc':
    			if ($image && $image['description'] != '') {
    				$widget_content .= '<div class="wppa-widget-text">' . stripslashes($image['description']) . '</div>';
    			}
    			break;
    	}
    	// Display the widget
    	echo $before_widget . $before_title . $widget_title . $after_title . $widget_content . $after_widget;
    }
    ?>

    Any ideas or help would be awesome!
    Thanks

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: WP Photo Album Plus] Load Multiple Random Images with widget function’ is closed to new replies.