Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter luckybeanz

    (@luckybeanz)

    Okay I am 100% sure this has something to do with the way Eazyest Gallery manages the clicks. If I change the option in Easyest Admin to link to attachment page when the thumbnail is clicked, then the above functions work as expected, linking to the attachment page https://127.0.0.1/luckybeanz/gallery/windsurfing-2/baja-mexico-8831/#main

    That doesn’t really help as my aim is to have the thumbnail link to a large image, 1024×637 in this case, in a lightbox and then have a link on the lightbox to the attachment page showing the full rez image, 4023×2053 in this case.

    So how exactly is Eazyest storing this information and how can I get the attachment page when the setting is set to show a large image not link to the attachment page.

    Thread Starter luckybeanz

    (@luckybeanz)

    This was due to a filter. What I ended up doing is writing a plugin that took the image URL and searched the DB for the attachment page then redirected it to the attachment page. The code is below

    if (!function_exists('link_to_attachment')) {
    	function link_to_attachment() {
         global $wpdb;	 
    
    	 //check to see if already run, and if so exit
    	 static $count=0;
    	  if ($count++)
           exit;
    
    		if (isset($_GET["url"])) {
    		   $ImageURL = $_GET["url"];
    		   $attachment_page_id  = $wpdb->get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts WHERE wposts.post_type = 'attachment' AND wposts.post_mime_type = 'image/jpeg' AND INSTR('%s',wposts.post_name)>0", $ImageURL) );
    		        if ($attachment_page_id == Null){
    				  wp_redirect( $ImageURL, 302); //if can't find attachment page id redirect to the current image file
    				 // echo "No Attachment Page $attachment_page";
    				  exit;
    				}else{
    wp_redirect( $attachment_page, 301);		  
    
    				  exit;
    				}
    		   }
    
    	  }
    
    	add_action('init', 'link_to_attachment',0);
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can't get attachment page link’ is closed to new replies.