function do_figure()
- Wie das HTML der Bilder mit ihren Angaben für die Quelle und Lizenzen im CODE WordPress ausgeben werden.
Funktion definieren
Es sind eine Reihe weitere Funktionen notwendig.
<?php function do_figure( $image ) { $img_src = wp_get_attachment_image_url( $image['ID'], 'large' ); $img_srcset = wp_get_attachment_image_srcset( $image['ID'], 'large' ); $figure = '<figure class="figure_container">'; $figure .= '<img src="' . esc_url( $img_src ) . '" srcset="' . esc_attr( $img_srcset ) .'" sizes="(max-width: 64rem) 87vw, 1024px" alt="' . $image['caption'] . '">'; $figure .= '<figcaption class="glossar_check pad">'; $figure .= '<p>' . $image['description'] . '</p>'; $figure .= '<small>Lizenz<br> ' . get_field( "lizenz", $image['ID'] )['label'] . '<br> <a href="' . get_field( "quelle", $image['ID'] ) . '" target="_blank">' . get_field( "quelle", $image['ID'] ) . '</a> </small>'; $figure .= '</figcaption>'; $figure .= '</figure>'; return $figure; }Funktion aufrufen und ausgeben
Die Function erwartet als input ein Wordpress Image Object.
<?php echo do_figure( $image );
Dieses #html wird an den Browser geliefert.
<figure class="figure_container"> <img src="http://localhost/code2c/wp-content/uploads/2018/09/9407011_31-1024x657.jpg" srcset="http://localhost/code2c/wp-content/uploads/2018/09/9407011_31-1024x657.jpg 1024w, http://localhost/code2c/wp-content/uploads/2018/09/9407011_31-300x193.jpg 300w, http://localhost/code2c/wp-content/uploads/2018/09/9407011_31-768x493.jpg 768w" sizes="(max-width: 64rem) 87vw, 1024px" alt="Former physicist, Tim Berners-Lee invented the World Wide Web as an essential tool for high energy physics at CERN from 1989 to 1994. Together with a small team he conceived HTML, http, URLs, and put up the first server and the first 'what you see is what you get' browser and html editor. Tim is now Director of the Web Consortium W3C, the International Web standards body based at INRIA, MIT and Keio University."> <figcaption class="glossar_check pad"> <p>Der Physiker Tim-Berners-Lee entwickelte zusammen mit einem kleinen Team essenzielle Tools für die bessere Erforschung von Physik. Neben <strong class="checked to_do">html</strong> entstanden so auch die Technologien <strong class="checked to_do">http</strong>, <strong class="checked to_do">url</strong>, und der erste <strong class="checked to_do">Browser</strong> und <strong class="checked to_do">Server</strong>. Heute ist Tim der Direktor vom Web Consortium W3C.</p> <small>Lizenz<br> CERN-GE-9407011<br> <a href="https://cds.cern.ch/record/39437/?ln=en" target="_blank">https://cds.cern.ch/record/39437/?ln=en</a> </small> </figcaption> </figure>
Anzeige im Browser

Der Physiker Tim-Berners-Lee entwickelte zusammen mit einem kleinen Team essenzielle Tools für die bessere Erforschung von Physik. Neben HTML entstanden so auch die Technologien HTTP, URL, und der erste Browser und Server. Heute ist Tim der Direktor vom Web Consortium W3C.
Lizenz der AbbildungCERN