Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php为wordpress中的images文件夹设置根目录_Php_Wordpress_Path_Root - Fatal编程技术网

使用php为wordpress中的images文件夹设置根目录

使用php为wordpress中的images文件夹设置根目录,php,wordpress,path,root,Php,Wordpress,Path,Root,我的问题是为图像设置根变量,而不使用php在Wordpress中写入所有路径。 我的情况是: <img src="http://localhost/business/wp-content/themes/enigma-child/images/sottocategorie/animaliDomestici/cane.jpg" class="img-thumbnail img-responsive"> 我想要这种情况($root=): 在wordpress中,我在哪里设置这个根

我的问题是为图像设置根变量,而不使用php在Wordpress中写入所有路径。 我的情况是:

<img src="http://localhost/business/wp-content/themes/enigma-child/images/sottocategorie/animaliDomestici/cane.jpg" class="img-thumbnail img-responsive">

我想要这种情况($root=):


在wordpress中,我在哪里设置这个根变量?有没有一种方法可以从图库中获取图像?
Thx for answers

因为您是从子主题引用的,所以动态调用图像的方式是使用
get\u stylesheet\u directory\u uri()
函数

例如,
/images/image.png“alt=“your image”>

对于$root作为变量,最好将其作为全局变量插入functions.php或header.php中。这样您就不会修改核心代码,而是从子主题进行扩展


我测试了您建议的代码,但它不起作用,因为我的情况是在交换机中使用img标记。我显示了我的情况:
案例1:echo(Animali domestic

);echo(“/images/sottocategorie/animalidometic/cane.jpg>”);中断
您尝试使用
/images/image.png“alt=”image“>
这是可行的,但是使用html格式的php代码。我的问题是将html代码反向转换为php,我无法阅读您向我展示的方式。请看这张图片以了解我的问题:您可以尝试使链接路径相对,就像这样
。我尝试使链接路径相对,但不起作用。显示链接的try相对路径:。问题出在哪里?无法很好地解释PHP开关内的html代码?
<img src="root/images/sottocategorie/animaliDomestici/cane.jpg" class="img-thumbnail img-responsive">