2013-03-20 64 views
0

我一直在努力尝试修改可能包含不同文件夹的字符串的每个部分。我在PhotoArtist主题中使用了Supersized jQuery滑块。如果你想看到它住在这里的链接:http://www.arjanbaagh.com/testsite/sliders-list/bridal-2013-collection/修改WordPress中的输出网址以包含另一个文件夹

我试图实现的是修改$output字符串以在文件名之前包含不同的文件夹。我正在尝试使用不同的缩略图进行预览。目前,滑块从主预览中拉出图像并动态缩放图像。下面是PHP代码显示在页面上的缩略图行:

$output .=" thumb : ". "'" . get_template_directory_uri() . "/framework/timthumb/timthumb.php?src=".thumb_link($element['img']) . "&w=300&h=150'}"; 

此输出以下网址:

http://www.arjanbaagh.com/testsite/wp-content/themes/photoartist-parent/framework/timthumb/timthumb.php?src=http://www.arjanbaagh.com/testsite/wp-content/uploads/2012/02/image02.jpg&w=300&h=150

所有我想要做的就是改变$output字符串,使其包含image02.jpg之前的另一个文件夹。因此,例如,我想将URL更改为:

http://www.arjanbaagh.com/testsite/wp-content/themes/photoartist-parent/framework/timthumb/timthumb.php?src=http://www.arjanbaagh.com/testsite/wp-content/uploads/2012/02/newfolder /image02.jpg & W = 300 & H = 150

我已经尝试在$输出字符串修改目录,但我只能改变字符串的开头或结尾。

任何帮助将不胜感激!

+0

在图片总是从'uploads'文件夹干? – adamdehaven 2013-03-20 18:19:37

+0

嗨@AdamD,是的,这是正确的。所有来自滑块的图像都来自上传文件夹。缩略图当前只是大型预览图像的动态缩小版本,因此缩略图不会存储在任何位置。我只是想将URL重定向到一个新的文件夹,我可以创建自定义thumbumbs。感谢您的帮助! – Raja 2013-03-20 18:22:24

回答

1

添加这个现有$output下面的字符串:

/* Set the $output URL to a variable */  
$url = explode('/', $output); 

/* Grab the last segment of the URL (image name and parameters) */ 
$lastSegment = end($url); // image02.jpg&w=300&h=150 

/* Grab the first part of the entire original $output URL before the image string */ 
$partialUrl = explode($lastSegment, $output); // gets first part of url before image02.jpg&w=300&h=150 

/* Grab the first returned value from $partialUrl, which is the string before the image name */ 
$firstHalf = $partialUrl[0]; // http://www.arjanbaagh.com/testsite/wp-content/themes/photoartist-parent/framework/timthumb/timthumb.php?src=http://www.arjanbaagh.com/testsite/wp-content/uploads/2012/02/ 

/* Add your directory */ 
$stringToAdd = 'newfolder/'; 

/* Final $output with your new directory in place */ 
$output = $firstHalf.$stringToAdd.$lastSegment 
+0

你是传奇!非常感谢你的帮助。你的代码工作(用一个小小的调整)。我将代码放在现有的$输出字符串下,并且瞧!我不得不改变$ partialUrl = explode('$ lastSegment',$ output);到$ partialUrl = explode($ lastSegment,$ output);没有引号,它的工作完美。你分解它的方式使得它更容易理解你是如何做到的。非常感谢你的帮助:) – Raja 2013-03-20 19:57:45

+0

没问题 - 对于引号中带有变量的错字,感到抱歉。我已经修复了其他人的答案:) – adamdehaven 2013-03-20 20:16:49

+0

太棒了,再次感谢@AdamD! :) – Raja 2013-03-20 20:54:25

相关问题