wordpress, 图片相对路径 function wp_get_attachment_url( $post_id =0 ) { $file_dir=dirname(__FILE__); $server_root=$_SERVER; $file_dir=substr($file_dir,strlen($server_root)); $file_dir=substr($file_dir,0,-12); if($file_dir!=\'\'){ $file_dir=\'/\'.substr($file_dir,1); } $post_id = (int) $post_id; if ( !$post =& get_post( $post_id ) ) return false; $url = \'\'; if ( $file = get_post_meta( $post->ID,\'_wp_attached_file\', true) ) { //Get attached file if ( ($uploads = wp_upload_dir())&& false === $uploads ) { //Get upload directory if ( 0 === strpos($file,$uploads) ) //Check that the upload base exists in the file location //$url = str_replace($uploads,$uploads, $file); //replace file location with url location $url=$file_dir.\"/wp-content/uploads/\".$file; elseif ( false !== strpos($file, \'wp-content/uploads\')) //$url = $uploads . substr($file, strpos($file, \'wp-content/uploads\') + 18 ); $url=$file_dir.\"/wp-content/uploads/\".$file; else //$url = $uploads .\"/$file\"; //Its a newly uploaded file, therefor $file is relative tothe basedir. $url=$file_dir.\"/wp-content/uploads/\".$file; } } if ( empty($url) ) //If any of the aboveoptions failed, Fallback on the GUID as used pre-2.7, not recomended to relyupon this. $url = get_the_guid( $post->ID ); if ( \'attachment\' != $post->post_type|| empty($url) ) return false; return apply_filters(\'wp_get_attachment_url\', $url, $post->ID ); } 3 cd lighttpd/ 5 vim lighttpd.conf 38 bzip2 \\ 39 lighttpd-mod-fastcgi \\ 40 lighttpd-mod-access \\ 41 cd /web/press 46 cd themes/ 53 vim functions.php 54 nano functions.php 55 vim functions.php 56 cd /opt/share/htdocs/press/wp-admin 58 cp options.php options.php-bak