Php wp all import自定义函数以替换图像URL中的属性
我使用WP All Import导入产品。我在尝试映射产品变化图像时遇到了一些问题 我的XML文件包含一个Php wp all import自定义函数以替换图像URL中的属性,php,wordpress,Php,Wordpress,我使用WP All Import导入产品。我在尝试映射产品变化图像时遇到了一些问题 我的XML文件包含一个 每个变体都有相同的产品名称,并且以这种方式通过不同的项目编号处理变体 <ItemNo>450042-02</ItemNo> <ItemNo>450042-05</ItemNo> <ItemNo>450042-07</ItemNo> 如果你把它拆了 450042&config=02将与450042-02匹配 4500
每个变体都有相同的产品名称,并且以这种方式通过不同的项目编号处理变体
<ItemNo>450042-02</ItemNo>
<ItemNo>450042-05</ItemNo>
<ItemNo>450042-07</ItemNo>
如果你把它拆了
将与450042-02匹配450042&config=02
将与450042-05匹配450042&config=05
,&format=l
(这表示大小图像 我认为图像编号与此无关)&format=s
/ImageServices/image.ashx?itemid={ItemNo[1]}&format=l&imagenumber=1
它将输出以下不起作用的内容
所以我需要将连字符改为&config=
wp all import接受自定义函数,任何人都知道只在图像部分将
{ItemNo[1]}
中的-
替换为&config=
的函数吗?似乎您正在尝试实现以下目标:
$string = '450042-02';
echo "\n";
// part before the -, itemid
print_r(substr($string, 0, strpos($string, "-")));
echo "\n";
//part after the -, config
print_r(substr($string, strpos($string, "-") + 1));
echo "\n";
虽然我从来没有使用过可湿性粉剂所有进口
但是这里引用
似乎可以在[]
方括号内运行php函数
因此,字段映射应该变成
/ImageServices/image.ashx?itemid=[substr({ItemNo[1]},0,strpos({ItemNo[1]},“-”))]&config=[substr({ItemNo[1]},strpos({ItemNo[1]},“-”)和format=l&imagenumber=1
我不确定的是,它是否能够处理+运算符等,但您可以尝试
如果它不起作用,那么您可以使用上面的代码(substr逻辑)创建自定义函数,如
get\u my\u itemid($string)
,get\u my\u config($string)
,然后在Img中使用它。URL而不是substr
我不知道我是否理解,只是str\u replace('-','&config=',$itemString)
?谢谢!这很有效[str_replace(“-”,“&config=“,{ItemNo[1]})]嘿,谢谢你的提示。这似乎起到了作用[str_replace(“-”,“&config=“,{ItemNo[1]})]。看起来我根本不需要自定义函数。
$string = '450042-02';
echo "\n";
// part before the -, itemid
print_r(substr($string, 0, strpos($string, "-")));
echo "\n";
//part after the -, config
print_r(substr($string, strpos($string, "-") + 1));
echo "\n";