简体   繁体   English

如何在php中的回声图像周围添加href?

[英]How to add href around echo image in php?

我正在尝试在下面的 x 图像周围添加永久链接()或简单的“href”链接。

echo '<img src="' . $image_src[0]  . '" width="100%" class="blog-image-border" />';
echo '<a href="'.the_permalink().'"><img src="' . $image_src[0]  . '" width="100%" class="blog-image-border" /></a>';

Try below code for.试试下面的代码。 image take link of post or page in while loop.图像在 while 循环中获取帖子或页面的链接。

if you want to get page/post url for image then use below code.如果您想获取图片的页面/帖子网址,请使用以下代码。

echo '<a href="'.get_the_permalink().'"><img src="' . $image_src[0]  . '" width="100%" class="blog-image-border" /></a>';

if you want to get current image url then use below code.如果您想获取当前图片网址,请使用以下代码。

echo '<a href="'.esc_url_raw( $image_src[0] ).'"><img src="' . esc_url_raw( $image_src[0] )  . '" width="100%" class="blog-image-border" /></a>';

This code is tested and working perfect to wrap link of image此代码经过测试,可以完美地包装图像链接

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

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