Regina Schaukrug: Shortcode oder eigene function.php in Wordpress

Beitrag lesen

Mit Deinem Konzept wird das nichts. Versuche erst mal herauszubekommen, wie das Auto (In dieser Reihenfolge: HTML, CSS, Javascript, Webserver, PHP, Wordpress) funktioniert bevor Du es tunst. Niemand ist in der Lage (und wenn, dann nicht des Willens), Dir das gesamte Wissen über HTML, CSS, Javascript, Webserver, PHP, Wordpress (in dieser Reihenfolge) in einem Forenbeitrag zu vermitteln. Deine Frage sieht aber so als wäre exakt das notwendig. Übe bitte erst mal an den kleinen Dingen, sonst wird Dir der Zusammenhang nie klar.

Lagere die Funktion in ein eigenes PHP-Skript aus:

<?php
#file: $_SERVER['DOCUMENT_ROOT']/zumGruss.php

header('Content-Type:text/plain; charset="utf-8"');

if (isset( $_GET['typ'] === 'schlapsig' ) ) {
   echo "Tach!";
} else {
   echo "Guten Tag!";
}

Bringe wo auch immer in Deinen Templates ETWAS wie

<script>
        function getGruss( typ=false ) {

            if ( typ = 'schlapsig' ) {
                typ = '?typ=schlapsig';
            } else {
                typ = '';
            }

            var xhttp = new XMLHttpRequest();
            
            xhttp.onreadystatechange = function() {
                if ( this.readyState == 4 && this.status == 200 ) {
                    document.getElementByID['gruss']=xhttp.responseText );
                }
            };
            
            xhttp.open( 'GET', '/zumGruss.php' + typ, true );
            xhttp.send();
        }
</script>

und natürlich

<p id='gruss'></p><!-- Hier wird die Meldung angezeigt -->

<button id='ButtonGrussNormal'>Normal</button>
<button id='ButtonGrussSchlaspig'>Schlaspig</button>
<!-- oder -->
<a id='LinkGrussNormal'>Normal</a>
<a id='LinkGrussSchlaspig'>Schlaspig</a>
<--und darunter ggf. -->
<script>
   document.getElementById('ButtonGrussNormal').onclick='getGruss()';
   document.getElementById('ButtonGrussSchlaspig').onclick='getGruss("schlapsig")';

   document.getElementById('LinkGrussNormal').onclick='getGruss()';
   document.getElementById('LinkGrussSchlaspig').onclick='getGruss("schlapsig")';
</script>

unter.

Alternativ kannst Du

  • http://DEIN_SERVER/zumGruss.php oder
  • http://DEIN_SERVER/zumGruss.php?typ=schlapsig

auch direkt aufrufen.