【问题标题】:Modify the output URL in WordPress to include another folder修改 WordPress 中的输出 URL 以包含另一个文件夹
【发布时间】:2025-12-01 05:35:01
【问题描述】:

我已经为此苦苦挣扎了好几天,试图修改可能包含不同文件夹的字符串的每一部分。我在 PhotoArtist 主题中使用 Supersized jQuery 滑块。如果您想现场观看,请点击链接:http://www.arjanbaagh.com/testsite/sliders-list/bridal-2013-collection/

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

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

这会输出以下 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/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/新文件夹/image02.jpg&w=300&h=150

我尝试修改 $output 字符串中的目录,但我只能更改字符串的开头或结尾。

任何帮助将不胜感激!

【问题讨论】:

  • 图片总是来自uploads 文件夹吗?
  • 嗨@AdamD,是的,没错。滑块中的所有图像都来自上传文件夹。缩略图目前只是大型预览图像的动态缩小版本,因此缩略图不会存储在任何地方。我只想将 URL 重定向到可以创建自定义缩略图的新文件夹。感谢您的帮助!

标签: php wordpress supersized


【解决方案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

【讨论】:

  • 你是个传奇!!非常感谢你的帮助。您的代码有效(稍作调整)。我将代码放在现有的 $output 字符串下,瞧!我确实必须更改 $partialUrl = explode('$lastSegment', $output);到 $partialUrl = explode($lastSegment, $output);没有引号,它工作得很好。你分解它的方式让你更容易理解你是如何做到的。非常感谢您的帮助:)
  • 没问题 - 对不起,引号中的变量的错字。我已经为其他人确定了答案:)