简体   繁体   English

如何使用href在php中调用图片?

[英]How do I call in an image in php using a href?

I have a bit of code that, using php, I want it to call in an image rather than what it is currently calling in (which is 'echo bloginfo('name');). 我有一些代码,使用php,我希望它在图像中调用而不是它当前正在调用的图像(即'echo bloginfo('name');)。 However, I am sadly PHP illiterate and have no idea how to do this with the 'a href' posted below. 但是,可悲的是,我是PHP文盲,不知道如何使用下面发布的'a href'做到这一点。 Could anyone help me call to /images/logo.png? 有人可以帮我打电话给/images/logo.png吗? Many thanks in advance! 提前谢谢了!

<h1><a href="<?php echo get_settings('home'); ?>"><?php echo bloginfo('name'); ?></a></h1>

The tag for add images is <img src=""> on the src attribute you need to write the url of the image you want (in your case /images/logo.png ) so, replacing the code you pasted 添加图像的标签是src属性上的<img src=""> ,您需要编写所需图像的url(在您的情况下为/images/logo.png ),因此,替换您粘贴的代码

<h1><a href="<?php echo get_settings('home'); ?>"><img src="/images/logo.png"></a></h1>

Take into account that the path to the image you are using now is a relative one (relative to the document requiring the image) so you probably want to have the absolute url instead. 考虑到您现在使用的图像路径是相对路径(相对于需要该图像的文档),因此您可能希望使用绝对URL。

What is the return of get_settings() function? get_settings()函数的返回值是什么? ==> name's Image? ==>名称的图片?
I think this code is OK, but you should check the return value of your function. 我认为这段代码可以,但是您应该检查函数的返回值。

...place at the beginning of you webpage, near the top with the rest of your PHP/JavaScript: ...放在网页的开头,与其他PHP / JavaScript放在顶部附近:

    <?php

    $image_name = '/images/logo.png';

    ?>

...In this are you place allof your HTML... ...在这里放置所有HTML ...

    <img src='<?php echo $image_name; ?>'>

Basically, you can have a variable named 'image_name' that you can have be anything. 基本上,您可以拥有一个名为“ image_name”的变量,可以是任何变量。

If you wanted the HREF link area to be a variable that could be changed as well, just do this: 如果您希望HREF链接区域是也可以更改的变量,请执行以下操作:

    <?php

    $image_name = '/images/logo.png';
    $image_url = 'http://www.google.com';

    ?>

Then... 然后...

    <a href='<?php echo $image_url; ?>' border='0'><img src='<?php echo $image_name; ?>'></a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM