URL引用图片的动态变化
我正在使用 Elementor 在 Wordpress 上设计一个网页,目前该页面的正文中有一个图像。
该图像使用“从 URL 插入”选项,而不是从媒体库中提取。我希望页面上有这样的功能,用户可以单击按钮,通过将 php 字符串传递到 URL 来切换显示的图像,这在理想情况下会更改图片的 URL。
目标是减少 Web 服务器本身的压力。图片 URL 结构是一致的,如下所示:
www.example.com/graphics/someregion_somevariable.png
是否可以利用 CSS 代码(在 Elementor 图片小部件内部)直接更改传递到网站 URL 的 php 字符串中引用图片的 URL?需要利用哪些 CSS 和 PHP 代码来执行此操作?谢谢你!
I am utilizing Elementor to design a webpage on Wordpress and currently have an image in the body of this page.
This image utilizes the "Insert from URL" option as opposed to pulling from the media library. I would like functionality on the page where a user can click buttons to switch which image is displayed by passing a php string into the URL, which would ideally change the URL of the picture.
The goal is to reduce strain on the web server itself. The picture URL structure is consistent, and is as follows:
www.example.com/graphics/someregion_somevariable.png
It is possible to leverage CSS code (inside the Elementor picture widget) to directly change the URL referenced picture off a php string passed into the website URL? What CSS and PHP code would need to be leveraged to execute this? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JavaScript 解决方案
使用 URL 参数指示要显示的图片:
https://example.com/page?picture=picture_1
https://example.com/page?picture=picture_2
code>https://example.com/page?picture=picture_3
您可以根据此 URL 参数有条件地加载特定图像:
现在您可以在页面上选择图像元素并将 src 更改为所需图片。
JavaScript Solution
Using URL params to indicate which picture to display:
https://example.com/page?picture=picture_1
https://example.com/page?picture=picture_2
https://example.com/page?picture=picture_3
You can conditionally load a specific image based on this URL Parameter:
Now you can select your image element on page and change the src to the required picture.