{"id":37069,"date":"2021-01-12T11:54:48","date_gmt":"2021-01-12T11:54:48","guid":{"rendered":"http:\/\/getshortcodes.com\/?post_type=docs&#038;p=37069"},"modified":"2021-01-12T11:54:49","modified_gmt":"2021-01-12T11:54:49","slug":"function-reference-su_get_gallery_slides","status":"publish","type":"docs","link":"https:\/\/getshortcodes.com\/docs\/function-reference-su_get_gallery_slides\/","title":{"rendered":"Function reference: su_get_gallery_slides()"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>su_get_gallery_slides( array $args )<\/code><\/pre>\n\n\n\n<p>Creates an array of slides for a gallery (image gallery, slider\/carousel, etc.), based on a simple and readable query string. This function is being used by the <a href=\"\/docs\/image-carousel\/\">Image Carousel<\/a> shortcode and can be utilized in custom shortcodes, created in the <a href=\"\/add-ons\/shortcode-creator\/\">Shortcode Creator<\/a> add-on.<\/p>\n\n\n<p class=\"h2\">Table of contents<\/p>\n\n<ol><li><a href=\"#parameters\">Parameters<\/a><\/li><li><a href=\"#settings\">Settings<\/a><ol><li><a href=\"#source\">source<\/a><\/li><li><a href=\"#link\">link<\/a><\/li><li><a href=\"#limit\">limit<\/a><\/li><li><a href=\"#random\">random<\/a><\/li><li><a href=\"#prefer_caption\">prefer_caption<\/a><\/li><\/ol><\/li><li><a href=\"#return\">Return<\/a><\/li><li><a href=\"#source--1\">Source<\/a><\/li><li><a href=\"#examples\">Examples<\/a><ol><li><a href=\"#getting-the-slides-data\">Getting the slides data<\/a><\/li><li><a href=\"#displaying-the-images\">Displaying the images<\/a><\/li><\/ol><\/li><\/ol><\/li><\/ol>\n\n\n<h2 class=\"wp-block-heading\" id=\"parameters\">Parameters<\/h2>\n\n\n\n<p>The function accepts a single argument, which must contain an array with settings.<\/p>\n\n\n\n<p><strong>$atts<\/strong><br>(array)(Required) An array with settings<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"settings\">Settings<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"source\">source<\/h3>\n\n\n\n<p>The query string to be used to query posts from the DB.<\/p>\n\n\n\n<p>Possible values:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>media: 1, 2, 3<\/code> (where 1, 2, 3 are attachment IDs)<\/li><li><code>media: recent<\/code><\/li><li><code>posts: 1, 2, 3<\/code> (where 1, 2, 3 are post IDs)<\/li><li><code>posts: recent<\/code><\/li><li><code>taxonomy: books\/1, 2, 3<\/code> (where books is the taxonomy slug, and 1, 2, 3 are term IDs)<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"link\">link<\/h3>\n\n\n\n<p>This setting determines which link will be created for a slide.<\/p>\n\n\n\n<p>Possible values are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>none<\/code> \u2013 no link needed, default<\/li><li><code>image<\/code> \u2013 the original full-size image URL<\/li><li><code>custom<\/code> \u2013 custom links can be set by editing an attachment, <a href=\"\/docs\/custom-links-in-image-carousel-and-custom-gallery-shortcodes\/\">learn more<\/a><\/li><li><code>attachment<\/code> \u2013 attachment page URL<\/li><li><code>post<\/code> \u2013 the original post permalink<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"limit\">limit<\/h3>\n\n\n\n<p>This setting sets max number of posts that will be queried. It can be used with the following <code>source<\/code> values: <code>posts: recent<\/code>, <code>media: recent<\/code>, and <code>taxonomy: books\/1, 2, 3<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"random\">random<\/h3>\n\n\n\n<p>Set the value to <code>yes<\/code> to shuffle the slides order. Possible values: <code>yes<\/code> and <code>no<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"prefer_caption\">prefer_caption<\/h3>\n\n\n\n<p>Set the value to <code>yes<\/code> to use image captions instead of image titles as a slide caption. Possible values: <code>yes<\/code> and <code>no<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"return\">Return<\/h2>\n\n\n\n<p>The function returns an array with slides data on success, <code>false<\/code> otherwise.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;\n\t&#91;\n\t\t'post_id': 1,\n\t\t'attachment_id': 1,\n\t\t'caption': 'Image caption',\n\t\t'link': 'https:\/\/example.com\/post-1\/',\n\t],\n]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"source--1\">Source<\/h2>\n\n\n\n<p>The most actual version of the source code can be found in the <a rel=\"noreferrer noopener\" href=\"https:\/\/plugins.trac.wordpress.org\/browser\/shortcodes-ultimate\/trunk\/includes\/functions-galleries.php\" target=\"_blank\">includes\/functions-galleries.php<\/a> file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"examples\">Examples<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"getting-the-slides-data\">Getting the slides data<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"media-library\">Media Library<\/h4>\n\n\n\n<p>The code below will create slides data based on the Media Library attachments with IDs 1, 2, and 3.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$slides = su_get_gallery_slides( &#91; 'source' =&gt; 'media: 1, 2, 3' ] );<\/code><\/pre>\n\n\n\n<p>The code below will create slides data out of the 10 last uploaded attachments.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$slides = su_get_gallery_slides(\n\t&#91;\n\t\t'source' =&gt; 'media: recent',\n\t\t'limit' =&gt; 10,\n\t]\n);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"posts\">Posts<\/h4>\n\n\n\n<p>The code below will get posts with IDs 2 and 3, and create slides data based on their featured images:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$slides = su_get_gallery_slides( &#91; 'source' =&gt; 'posts: 2, 3' ] );<\/code><\/pre>\n\n\n\n<p>The code below will get 10 latest posts, and create slides data based on their featured images:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$slides = su_get_gallery_slides(\n\t&#91;\n\t\t'source' =&gt; 'posts: recent',\n\t\t'limit' =&gt; 10,\n\t]\n);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"taxonomy-terms\">Taxonomy terms<\/h4>\n\n\n\n<p>The code below will get 2 latest posts from the <code>category<\/code> with ID <code>1<\/code> and generate slides data based on their featured images:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$slides = su_get_gallery_slides(\n\t&#91;\n\t\t'source' =&gt; 'taxonomy: category\/1',\n\t\t'limit' =&gt; 2,\n\t]\n);<\/code><\/pre>\n\n\n\n<p>The code below will get 2 latest posts from the terms with IDs <code>2<\/code> and <code>3<\/code> in the <code>books<\/code> taxonomy, and generate slides data from their featured images:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$slides = su_get_gallery_slides(\n\t&#91;\n\t\t'source' =&gt; 'taxonomy: books\/2,3',\n\t\t'limit' =&gt; 2,\n\t]\n);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"displaying-the-images\">Displaying the images<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Get the slides data\n$slides = su_get_gallery_slides( &#91; ... ] );\n\n\/\/ Loop the received slides\nforeach ( $slides as $slide ) {\n\n\t\/\/ Display an &lt;img&gt; tag by the slide's attachment_id\n\techo wp_get_attachment_image(\n\t\t$slide&#91;'attachment_id'],\n\t\t'post-thumbnail'\n\t);\n\n\t\/\/ Display the slide caption\n\techo $slide&#91;'caption'];\n\n\t\/\/ Display the slide link\n\techo $slide&#91;'link'];\n\n}<\/code><\/pre>\n","protected":false},"featured_media":0,"template":"","docs_category":[24],"class_list":["post-37069","docs","type-docs","status-publish","hentry","docs_category-api"],"_links":{"self":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs\/37069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/types\/docs"}],"wp:attachment":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/media?parent=37069"}],"wp:term":[{"taxonomy":"docs_category","embeddable":true,"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs_category?post=37069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}