Joy
(@joyously)
What if you simply put the links to the images in the page from the start, instead of having to look it up when clicked?
If you are writing PHP, you don’t need the plugin for the snippet shortcode. You can call the function directly. Shortcodes are for content areas where you can’t put PHP. They are expanded right before the content is output by the theme.
HI Joy
I need the links because different links give different images displayed.I did further tests: if in the snippet where I have
if(isset($_GET['link'])){
I insert global $url1 and I put global $usrl1 in the snippet named [xyz-ips snippet="echo-url1"] as well, the echo command works. Unfortunately in the web site page I have
<img src="[xyz-ips snippet="echo-url1"]"> and the element src can contain only the echo command no other.
Can you clarify me your point of view about “can call funcion directly” if this can help to fix this issue.
Thanks
Hi Joy,
please do not consider previous post.
I have done further test following your suggestion of functions.php. In that file I put the following:
global $my_var;
//$my_var="http://localhost/WpSito2/Images/Site_library_page/def_img.png"; both don't work
$my_var=".\WpSito2\Images\Site_library_page\def_img.png";
Then in the php-snippet at the top of the WP page I put :
global $my_var;
if(isset($_GET['link'])) {
$link=$_GET['link'];
if ($link == '1'){
$my_var=".\WpSito2\Images\Site_library_page\Standard\img1.png";
}
In the Web page i have:
<div class="divi_1_psl" ><img class="img_psl" src="[xyz-ips snippet="echo-url1"]">
And in the [xyz-ips snippet="echo-url1]the content is:
<?php
echo $GLOBALS['$my_var'];
?>
So if in $my_var , in functions.php, I set a simple text e.g “Hello” and in the top-snippet I set $my_var=“Goodbye” ,when I load the Web page “Hello” is displayed and clicking the link , condition is $link=1, I see “Goodbye”.It works!But using image ,instead of the text, no! Do you have any idea in order to help in figure out this problem ?
Many thanks
-
This reply was modified 5 years, 11 months ago by
valerio.
@valgo54
What are you trying to achieve? Right now, it’s unclear to me why you’re trying to do something very complicated that instead could easily be done with normal static HTML content.
Hi,
what I want to achieve is to click different links in order to display different images. I try to make a summary:
In my web page I have 2 links.When I click link1 in $my_var I should set image’s path 1, when I click link2 in $my_var I have to set image’s path 2. What is it not running is
the echo command that should run in a html content like this
<div class="divi_3_psl" ><img class="img_psl" src="<?php echo $my_var ?>"
Let me know if you need more details.
Thanks
PHP is server-side, and click-based actions are client-side. Looks to me like you should be using Javascript to accomplish your task.
Hi ,
ok per Javascript, do you have some advices/links I can follow ?
Question:If I have in functions.php a define like this:
define("THEME_IMG_PATH","http://localhost/WpSite/Images");
and in WP page I have:
<div ><img src="<?php echo THEME_IMG_PATH; ?>/img1.png"></div>
Can the echo command display img1?
I run a test but it doesn’t work.
Thanks for your help