如何使用 href 调用 php 中的图像?

发布于 2024-12-13 14:21:21 字数 294 浏览 2 评论 0原文

我有一些代码,使用 php,我希望它调用图像而不是当前调用的内容(即“echo bloginfo('name');”)。然而,遗憾的是我不懂 PHP,并且不知道如何使用下面发布的“a href”来做到这一点。谁能帮我打电话到/images/logo.png?非常感谢!

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

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');). However, I am sadly PHP illiterate and have no idea how to do this with the 'a href' posted below. Could anyone help me call to /images/logo.png? Many thanks in advance!

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

靖瑶 2024-12-20 14:21:21

添加图像的标签是 src 属性上,您需要编写所需图像的 url(在您的情况下 /images/logo.png) 因此,替换您粘贴的代码

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

考虑到您现在使用的图像的路径是相对路径(相对于需要图像的文档),因此您可能想要改为使用绝对网址。

The tag for add images is <img src=""> on the srcattribute you need to write the url of the image you want (in your case /images/logo.png) so, replacing the code you pasted

<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.

你与清晨阳光 2024-12-20 14:21:21

...放置在网页的开头,靠近顶部以及 PHP/JavaScript 的其余部分:

    <?php

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

    ?>

...在此放置所有 HTML...

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

基本上,您可以有一个名为“image_name”的变量可以是任何东西。

如果您希望 HREF 链接区域也是一个可以更改的变量,只需执行以下操作:

    <?php

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

    ?>

然后...

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

...place at the beginning of you webpage, near the top with the rest of your PHP/JavaScript:

    <?php

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

    ?>

...In this are you place allof your HTML...

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

Basically, you can have a variable named 'image_name' that you can have be anything.

If you wanted the HREF link area to be a variable that could be changed as well, just do this:

    <?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>
不忘初心 2024-12-20 14:21:21

get_settings() 函数的返回值是什么? ==>名字的图片?
我认为这段代码没问题,但你应该检查函数的返回值。

What is the return of get_settings() function? ==> name's Image?
I think this code is OK, but you should check the return value of your function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文