php 使用 MAMP 时如何将图像添加到 wordpress 主题?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8888611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:42:43  来源:igfitidea点击:

How to add images to a wordpress theme when working on MAMP?

phpimagewordpresswordpress-themingmamp

提问by Sophie

I am new to MAMP and I am developing a theme I designed. However I can't seem to get the images to render. I am using a clear theme I got from starkerstheme.comWhen adding an image directly to the code I used:

我是 MAMP 的新手,我正在开发我设计的主题。但是我似乎无法渲染图像。我正在使用从starkerstheme.com获得的清晰主题 当直接向我使用的代码添加图像时:

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

But the image is not showing up, also I tried to add it to the media library and it's still not rendering.

但是图像没有显示出来,我也尝试将它添加到媒体库中,但它仍然没有渲染。

回答by Robert Zelník

This works for me:

这对我有用:

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

See get bloginfo()function for more info.

有关更多信息,请参阅get bloginfo()函数。

回答by ismail

You can use the following code to add an image. This works for me:

您可以使用以下代码添加图像。这对我有用:

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

回答by demsley

<?php echo get_template_directory_uri(); ?> 

as suggested gets the PARENT theme, which is OK but if you've developed a child theme (as recommended by WordPress people) you need:

按照建议获取 PARENT 主题,这没问题,但如果您开发了子主题(由 WordPress 人员推荐),您需要:

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

回答by Mina Ragaie

Just go to your dashboard and upload your picture in the media section, then select it you'll see the image options .. then copy it's url <img src="your/copied/url"/>This aslo works for me in localhost

只需转到您的仪表板并在媒体部分上传您的图片,然后选择它,您将看到图像选项..然后复制它的网址 <img src="your/copied/url"/>这也适用于我在本地主机

回答by chef1974

<?php bloginfo('template_directory'); ?>/

use for internal root folder in images to place on theme on wordpress. The forward slash is needed for the image to show

用于图像中的内部根文件夹以放置在 wordpress 的主题上。显示图像需要正斜杠

回答by Eve Freeman

You might need to do the full <img src="<?php echo $theme; ?>/images/logo.png"/>

你可能需要做完整的 <img src="<?php echo $theme; ?>/images/logo.png"/>

UpdateI didn't read your question closely enough. If you're using the media library for the image, you'll need to specify the actual path to the image. You can figure this out from within the media library, but it's probably site_url/wp-content/uploads/2012/01/filename.jpg

更新我没有仔细阅读你的问题。如果您对图像使用媒体库,则需要指定图像的实际路径。您可以从媒体库中弄清楚这一点,但这可能是site_url/wp-content/uploads/2012/01/filename.jpg

In short, if you uploaded it in media, it wouldn't actually be in your theme.

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

回答by Paul Dessert

Remove the =after <?

删除=<?

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

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

in fact, I'd probably do something like this:

事实上,我可能会做这样的事情:

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

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