• pvanbavel

    (@pvanbavel)


    I’m using “Photo Gallery” plug-in and W3-data.
    Then there is a page where I want to display one gallery (of photos) per user.
    So using w3-data I generate the short-codes that I would like to have executed.

    An example of a generated short-code is:
    [Best_Wordpress_Gallery id=”21″ gal_title=”Name of User”]

    The generated short-codes are correct; if i hard-code the generated codes they generate the wanted galleries.

    For some reason it seems not possible to immediately execute the generated short-code.

    What is the best way to get the desired result.

    I’ve tried to use a plugin to execute the PHP code, But that doesn’t work!??

    Insert PHP
    Run PHP code inserted into WordPress posts and pages.
    Version 1.3 | By Will Bontrager Software, LLC

    [insert_php]
          echo do_shortcode("{{Best_Wordpress_Gallery}}");
     [/insert_php]
Viewing 2 replies - 1 through 2 (of 2 total)
  • girlieworks

    (@girlieworks)

    Hi, @pvanbavel. Have you tried it this way:

    echo do_shortcode( '[Best_Wordpress_Gallery id="21" gal_title="Name of User"]' );
    Thread Starter pvanbavel

    (@pvanbavel)

    Thnx. I hadn’t tried this before but this code works fine
    <?php echo do_shortcode( '[Best_Wordpress_Gallery id="21" gal_title="Name of User"]' ); ?>

    BTW, the [insert_php] shortcode does not work.

    I’ve now removed all code from the WordPress Page and put it into a template file. So executing PHP is no problem anymore.

    However I still have a problem with my page and that is that the above solution is hardcoded.

    The short-code string is correctly contained within {{Best_Wordpress_Gallery}}
    If a put {{Best_Wordpress_Gallery}} into a variable and put that variable into the below statement, things don’t work anymore.
    What am I doing wrong?

    Following is the complete source:

    <head>
    
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
    <link rel="stylesheet" href="http://www.w3schools.com/lib/w3data.js">
    <script src="http://www.w3schools.com/lib/w3data.js"></script>
    
    <script>
    var Artists = {"artiesten":[
        {"Naam":"User-1","Discipline":"Schilderen", "Best_Wordpress_Gallery":"[Best_Wordpress_Gallery id=\"20\" gal_title=\"User-1\"]"},
        {"Naam":"User-2","Discipline":"Schilderen", "Best_Wordpress_Gallery":"[Best_Wordpress_Gallery id=\"21\" gal_title=\"User-2\"]"},
        {"Naam":"User-3","Discipline":"Schilderen", "Best_Wordpress_Gallery":"[Best_Wordpress_Gallery id=\"21\" gal_title=\"User-3\"]"},
        {"Naam":"User-4","Discipline":"Schilderen", "Best_Wordpress_Gallery":"[Best_Wordpress_Gallery id=\"21\" gal_title=\"User-4\"]"}
    ]};
    </script>
    
    </head>
    <body>
        <section id="index" class="w3-container w3-section w3-padding-small">
            <nav class="w3-top w3-sidenav w3-sand w3-animate-left w3-margin-top" style="display:none">
                <a href="javascript:void(0)" onclick="w3_close()"  class="w3-closenav w3-large w3-pale-yellow w3-center">Close &times;</a>
                <ul id="id03"  class="w3-container w3-ul" onmouseleave="w3_close()">
                    <li class="w3-border-0" w3-repeat="artiesten" ><a onmouseclick="w3_close()" href="#{{Naam}}" >{{Naam}}: {{Discipline}}</a></li>
                </ul>
            </nav>
            <div id="rest" class="w3-container w3-rest"> </div>
        </section>
    
        <section id="Per Kunstenaar" class="w3-container ">
                <ul id="id04"  class="w3-container w3-ul">
                    <li class="w3-border-0" w3-repeat="artiesten" >
                        <div class="w3-container w3-center ">
                            <h3 class="w3-container w3-margin-top">{{Naam}}</h3>
    
                            {{Best_Wordpress_Gallery}}
    
                            <?php
                            echo do_shortcode( '[Best_Wordpress_Gallery id="21" gal_title="User-2"]' );
                            ?>
    
                        </div>
                        <div class="w3-container w3-center w3-margin-top">
                            <span class="w3-opennav  w3-large w3-border " onclick="w3_open()">☰ Namenlijst </span>
                                                                                       <!--  "☰" : Unicode code for menu hamburger   -->
                        </div>
    
                    </li>
                </ul>
            </div>
    
        </section>
    
    <script type="text/javascript" charset="utf-8" async defer>
        w3DisplayData("id03", Artists);
    </script>
    <script type="text/javascript" charset="utf-8" async defer>
        w3DisplayData("id04", Artists);
    </script>
    <script type="text/javascript" charset="utf-8" async defer>
        function w3_open() {
            document.getElementsByClassName("w3-sidenav")[0].style.width = "20%";
            document.getElementsByClassName("w3-sidenav")[0].style.display = "block";
        }
    </script>
    <script type="text/javascript" charset="utf-8" async defer>
        function w3_close() {
            document.getElementsByClassName("w3-sidenav")[0].style.display = "none";
        }
    </script>
    
    </body>

    The result should be a separate section per artist, consisting of his/her name, a small photo gallery and a “Namenlijst” (=’NameList’) button

    Much appreciated if you could help me out.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘executing generated shortcodes’ is closed to new replies.