Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can insert your images in the gallery without importing it into your post. Then, in the single post template, you can query the images attached to the post to display them.</p> <p>Attachments are just posts attached to a post, so let’s use get_posts():</p> <pre><code>function get_post_images($post) { $args = array( 'post_type' =&gt; 'attachment', // Images attached to the post 'numberposts' =&gt; -1, // Get all attachments 'post_status' =&gt; null, // I don’t care about status for gallery images 'post_parent' =&gt; $post-&gt;ID, // The parent post 'exclude' =&gt; get_post_thumbnail_id($post-&gt;ID), // Exclude the thumbnail if you want it on your article list but not inside an article 'post_mime_type' =&gt; 'image', // The attachment type 'order' =&gt; 'ASC', 'orderby' =&gt; 'menu_order ID', // Order by menu_order then by ID ); return get_posts($args); } </code></pre> <p>I suggest to place this function in the functions.php file.</p> <p>In your single.php file:</p> <pre><code>&lt;ul&gt; &lt;?php $images = get_post_images($post); foreach ($images as $image): ?&gt; &lt;li&gt;&lt;?php echo wp_get_attachment_image($image-&gt;ID, 'medium'); ?&gt;&lt;/li&gt; &lt;?php endforeach; ?&gt; &lt;/ul&gt; </code></pre> <p>WP Codex links:</p> <ul> <li><a href="http://codex.wordpress.org/Template_Tags/get_posts" rel="nofollow">get_posts()</a></li> <li><a href="http://codex.wordpress.org/Function_Reference/WP_Query#Parameters" rel="nofollow">Query parameters</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload