{"id":6490,"date":"2013-07-24T00:00:00","date_gmt":"2013-07-23T22:00:00","guid":{"rendered":"https:\/\/waltersblog.ch\/2013\/07\/24\/zufallsbilder-in-wordpress\/"},"modified":"2013-07-24T00:00:00","modified_gmt":"2013-07-23T22:00:00","slug":"zufallsbilder-in-wordpress","status":"publish","type":"post","link":"https:\/\/walterlernt.ch\/blog\/zufallsbilder-in-wordpress\/","title":{"rendered":"Zufallsbilder in WordPress"},"content":{"rendered":"<h3>Wie setzt man Zufallsbilder in den Content-Bereich einer Website ein?<\/h3>\n<p>Viele von uns nutzen das Galerie-Plugin NextGen Gallery. Damit k\u00f6nnen wir unz\u00e4hlige Galerien erstellen und verwalten. Mit einem kleinen Trick, den ich in diesem Video zeige, kann man auch damit Zufallsbilder aus einer bestimmten Galerie anzeigen.<\/p>\n<p><iframe loading=\"lazy\" title=\"Random Images in WordPress\" src=\"https:\/\/player.vimeo.com\/video\/70882802?dnt=1&amp;app_id=122963\" width=\"500\" height=\"281\" frameborder=\"0\" allow=\"autoplay; fullscreen; picture-in-picture; clipboard-write\"><\/iframe><\/p>\n<h3>PHP-Code f\u00fcr functions.php<\/h3>\n<p>Dies ist der Code, den man in functions.php am Ende anh\u00e4ngen muss:<\/p>\n<p>[php]<\/p>\n<p>function randomimage( $atts ) {<br \/>\nextract( shortcode_atts( array(<br \/>\n&#8216;galleryid&#8217; =&amp;gt; 1,<br \/>\n&#8216;imgclass&#8217; =&amp;gt; &#8216;noclass&#8217;<br \/>\n), $atts ) );<\/p>\n<p>global $wpdb;<br \/>\n$sql = &quot;SELECT * FROM &quot;.$wpdb-&amp;gt;prefix.&quot;ngg_pictures<br \/>\nJOIN &quot;.$wpdb-&amp;gt;prefix.&quot;ngg_gallery ON (galleryid = gid)<br \/>\nWHERE galleryid = &quot;.$galleryid.&quot; AND pid &amp;gt;= RAND() * (SELECT MAX(pid) FROM &quot;.$wpdb-&amp;gt;prefix.&quot;ngg_pictures WHERE galleryid=&quot;.$galleryid.&quot;) LIMIT 1&quot;;<br \/>\n$image = $wpdb-&amp;gt;get_row($sql,ARRAY_A);<br \/>\nif(!empty($image))<br \/>\nreturn &#8216;&lt;img class=&quot;&#8217;.$imgclass.&#8217;&quot; alt=&quot;&quot; src=&quot;&#8217;.get_bloginfo(&#8216;url&#8217;).&#8217;\/&#8217;.$image[&#8216;path&#8217;].&#8217;\/&#8217;.$image[&#8216;filename&#8217;].&#8217;&quot; \/&gt;&#8217;;<br \/>\nelse<br \/>\nreturn &#8221;;<br \/>\n}<br \/>\nadd_shortcode( &#8216;randomimage&#8217;, &#8216;randomimage&#8217; );<br \/>\n[\/php]<\/p>\n<h3>Weiterf\u00fchrende Infos:<\/h3>\n<ul>\n<li>Wie und warum man in WordPress ein Child Theme erstellt<\/li>\n<li style=\"text-align: left;\"><a href=\"http:\/\/wordpress.org\/plugins\/nextgen-gallery\/\" target=\"_blank\" rel=\"noopener\">WordPress-Plugin NextGen Gallery<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>So baut man ein Zufallsbild in WordPress ein.<\/p>\n","protected":false},"author":1,"featured_media":83058,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[263],"tags":[43,30,44,27,20],"class_list":["post-6490","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress-webdesign","tag-child-theme","tag-code","tag-screencast","tag-technik","tag-websites-und-technik"],"_links":{"self":[{"href":"https:\/\/walterlernt.ch\/blog\/wp-json\/wp\/v2\/posts\/6490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walterlernt.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walterlernt.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walterlernt.ch\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/walterlernt.ch\/blog\/wp-json\/wp\/v2\/comments?post=6490"}],"version-history":[{"count":0,"href":"https:\/\/walterlernt.ch\/blog\/wp-json\/wp\/v2\/posts\/6490\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/walterlernt.ch\/blog\/wp-json\/wp\/v2\/media\/83058"}],"wp:attachment":[{"href":"https:\/\/walterlernt.ch\/blog\/wp-json\/wp\/v2\/media?parent=6490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walterlernt.ch\/blog\/wp-json\/wp\/v2\/categories?post=6490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walterlernt.ch\/blog\/wp-json\/wp\/v2\/tags?post=6490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}