Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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 在使用MAMP时,如何向wordpress主题添加图像?_Php_Image_Wordpress_Wordpress Theming_Mamp - Fatal编程技术网

Php 在使用MAMP时,如何向wordpress主题添加图像?

Php 在使用MAMP时,如何向wordpress主题添加图像?,php,image,wordpress,wordpress-theming,mamp,Php,Image,Wordpress,Wordpress Theming,Mamp,我是MAMP的新手,我正在开发一个我设计的主题。然而,我似乎无法得到图像渲染。我使用的是一个清晰的主题 将图像直接添加到我使用的代码时: <img src="<?= $theme ?>/images/logo.png"/> /images/logo.png/> 但是图像没有显示,我也尝试将其添加到媒体库,但它仍然没有呈现。在之后删除=,您可能需要执行完整的/images/logo.png/> 更新我没有仔细阅读你的问题。如果要将媒体库用于图像,则需要指定图像的实际路径

我是MAMP的新手,我正在开发一个我设计的主题。然而,我似乎无法得到图像渲染。我使用的是一个清晰的主题 将图像直接添加到我使用的代码时:

<img src="<?= $theme ?>/images/logo.png"/>
/images/logo.png/>

但是图像没有显示,我也尝试将其添加到媒体库,但它仍然没有呈现。

之后删除
=
,您可能需要执行完整的
/images/logo.png/>

更新我没有仔细阅读你的问题。如果要将媒体库用于图像,则需要指定图像的实际路径。你可以从媒体库中找到答案,但可能是
site\u url/wp content/uploads/2012/01/filename.jpg

简而言之,如果你把它上传到媒体上,它实际上就不会出现在你的主题中。

这对我很有用:

<img src="<?php echo get_bloginfo('template_url') ?>/images/logo.png"/>
<img src="<?php echo get_template_directory_uri(); ?>/images/filename.png">
/images/logo.png/>

有关更多信息,请参阅函数。

只需转到您的仪表板,在“媒体”部分上载图片,然后选择它,您将看到图像选项。然后复制它的url
这也适用于我在localhost中使用
/
您可以使用以下代码添加图像。这对我很有用:

<img src="<?php echo get_bloginfo('template_url') ?>/images/logo.png"/>
<img src="<?php echo get_template_directory_uri(); ?>/images/filename.png">
/images/filename.png”>

如建议的那样,获取父主题,这是可以的,但是如果您已经开发了子主题(如WordPress人员所建议的),您需要:

<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/Logo.png">
/img/Logo.png>
2021年

只需将图像命名为screenshot.png[建议的图像大小(当前)为1200px宽900px],并将其放在主题的顶级目录(style.css文件所在的位置)


这就是你所需要做的。

我想没有,我该如何定义它?你必须发布更多的代码才能回答这个问题。/img/logo.png“alt=”site logo“/>当你使用子主题时。如果使用父主题,请使用get_template_directory_uri()函数代替et_stylesheet_directory_uri()。