WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Subsite images not showing up in 3.5.1 (6 posts)

  1. AsraiLight
    Member
    Posted 11 months ago #

    I have a brand new WP multisite network (v 3.5.1) on sub-directories. I'm getting an error with the images, where the subsites won't display them properly, but they are being uploaded correctly. I'm pretty sure all I need to do is add the correct RewriteRule to the .htaccess file in the main site, as such:

    When an image is called from anywhere in the subsite, the URL is: example.com/subsitename/assets/sites/#/foo.jpg. I want to change it so that the image actually pulls from: example.com/assets/sites/#/foo.jpg, where subsitename, #, and foo.jpg are all variables.

    It seems like this should be really simple, but I'm having a hard time finding the right syntax or an example of someone else who has solved this issue. Does anyone know the proper RewriteRule I would add?

    My current .htaccess file contains this:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]
  2. AsraiLight
    Member
    Posted 11 months ago #

    Well, after a bit of trial and error and trying different RewriteRule formats, I finally stumbled on one that works. I added this to my .htaccess file:

    RewriteRule ^([_0-9a-zA-Z-]+/)assets/sites/(.*)$ assets/sites/$2 [L]

    Now images that show up in posts are working beautifully. Unfortunately, the images that are called through the theme with timthumb are not working, which seems to be a common issue.

    I've seen some code that can be added to the theme's functions.php file from older versions of WordPress, which deals with the /files and /blogs.dir directories. But since 3.5.1 (and my particular settings) don't deal with those directories, how can I fix this timthumb issue? I would think that the new RewriteRule would have fixed it already, but apparently not.

  3. The problem is timthumb. The script you have calling may be doing it wrong.

  4. AsraiLight
    Member
    Posted 11 months ago #

    I figured that was the case, but how do I fix it? What is the proper way for the theme to call timthumb in the case of subsites?

    This is how my theme is calling it now in the header:

    EDIT (now with the full function):

    function get_thumb($wsize = '300', $hsize = '200', $src, $wrap, $align = 'c'){<br />
    	global $post;<br />
    	$theimage = '';<br />
    	if (!$src) {<br />
    		$src = wp_get_attachment_url( get_post_thumbnail_id($post->ID ) );<br />
    	}<br />
    	$first_img = '/'.THEME_PATH . '/inc/timthumb.php?src='.$src.'&h='.$hsize.'&w='.$wsize.'&zc=1&a='.$align.'&try-permalink=true';<br />
    	if($wrap){<br />
    		if (get_post_thumbnail_id($post->ID )) {<br />
    			if(get_post_meta($post->ID, 'link', true)) {<br />
    				$theimage = '<a>ID, 'link', true).'" target="_blank">';<br />
    			}<br />
    			$theimage .= '<img src="'.$first_img.'" />';<br />
    			if(get_post_meta($post->ID, 'link', true)) {<br />
    				$theimage .= '</a>';<br />
    			}<br />
    		}<br />
    	}else{<br />
    		$theimage = $first_img;<br />
    	}<br />
    	return $theimage;<br />
    }
  5. AsraiLight
    Member
    Posted 11 months ago #

    So no one knows how to fix timthumb in WordPress multisite 3.5.1? I've found plenty of references on how to fix it in earlier versions of WordPress, but not this one. I'm not even sure where to start.

  6. AsraiLight
    Member
    Posted 11 months ago #

    OK, I found a method that works. I'm not sure if it's the most elegant, but at least in my particular case, with a custom media upload folder, this is functioning.

    I changed my code from this:

    $first_img = '/'.THEME_PATH . '/inc/timthumb.php?src='.$src.'&h='.$hsize.'&w='.$wsize.'&zc=1&a='.$align.'&try-permalink=true';

    To this:

    $result = strstr($src, 'assets');
    $first_img = '/' . THEME_PATH . '/inc/timthumb.php?src='.$result.'&h='.$hsize.'&w='.$wsize.'&zc=1&a='.$align.'&try-permalink=true';

    This essentially grabs the $src variable, which has been defined in timthumb.php, and removes the sub-directory URL for the sub-site before it returns the image upload folder.

    I'm now having an issue with the image getting cached and not refreshing properly, but I'm guessing that has more to do with the pagespeed optimization that is installed on my domain rather than Timthumb and WordPress.

Reply

You must log in to post.

About this Topic