• Hello, I have a WP page with some links to click. Every time a link is clicked some images are displayed , each link clicked show different images. To do that I am using PHP to GET the link clicked. With plugin Insert PHP code snippet I manage the event after the link is clicked with the following:

    
    if(isset($_GET['link'])){
       $link=$_GET['link'];
       if ($link == '1'){
           $url1=  "https://localhost\Images\Site_Library\Standard\\"  . $img1 . ".png";
       }
       if ($link == '2'){
           $url2= ".\WpSito2\Images\Site_library_page\Standard\\" . $img2 . ".png";
       }
    }
    

    I am in trouble when I try to echo the image related to link1 or link2 with the following code and short-code:

    
    <?php
    echo $url1
    ?>
    Shortcode [xyz-ips snippet="echo-url1"] 
    
    <div class="divi_1_psl" ><img class="img_psl" src="[xyz-ips snippet="echo-url1"]"></div> 
    

    Surfing internet looking for a solution I didn’t solve.It’s seems that WP does not support netest code.
    Do you anyone have any idea in order to run nested code or to have an alternative solution regarding my issue.
    Thanks in advance

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

    Thread Starter valerio

    (@valgo54)

    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

    Thread Starter valerio

    (@valgo54)

    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="https://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 4 years, 4 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.

    Thread Starter valerio

    (@valgo54)

    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

    Dion

    (@diondesigns)

    PHP is server-side, and click-based actions are client-side. Looks to me like you should be using Javascript to accomplish your task.

    Thread Starter valerio

    (@valgo54)

    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","https://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

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Nested echo php code’ is closed to new replies.