title: Extract WordPress post attachments to unordered list outside of post
body: <p>I am trying to:</p>
  
  <ol>
  <li>Search a WP post for attachments (img and iframes)</li>
  <li>Move these outside of the post to a location earlier in the code hierarchy</li>
  <li>Present each one as a list-item in an unordered list, so that they are available to various slider/gallery plugins.</li>
  </ol>
  
  <p>The problem is, I can't see how to cycle through the items to assign <code>&lt;li&gt;</code> tags while also dynamically adding a wrapper <code>&lt;ul&gt;</code> if one is called for.</p>
  
  <p>Currently, I have this code, but am not experienced enough with jQuery to know what I'm doing wrong:</p>
  
  <pre><code>jQuery("document").ready (function(){
  
     jQuery(".para img, .para iframe").(function(){
      var nUl = jQuery("&lt;ul&gt;&lt;/ul&gt;");
      nUl.prependTo(jQuery(this).parents(".content-inset-wrap"));
   })
   jQuery(this).each(function(){
    var nLi = jQuery("&lt;li&gt;&lt;/li&gt;");
    nLi.appendTo(nUl);
    nLi.append(this);
  
  })
  </code></pre>
  
  <p>});</p>
  
  <p>I am aware that there may be an alternate way of doing this, using a direct WP query for post attachments, but have absolutely no idea how this works; and I don't see any reason why not to attempt it in straight up js as above. And I suspect the <code>&lt;ul&gt;</code> and <code>&lt;li&gt;</code> looping issue would remain in any case. </p>
  
  <p>For what it's worth, this code does what I'm trying to do but presents the looping issue, as each image or iframe found gets its own <code>&lt;ul&gt;</code> as well as <code>&lt;li&gt;</code>:</p>
  
  <pre><code>jQuery("document").ready (function(){
  jQuery(".para img, .para iframe").each(function(){
  
    var nUl = jQuery("&lt;ul&gt;&lt;/ul&gt;");
    var nLi = jQuery("&lt;li&gt;&lt;/li&gt;");
  
    nUl.prependTo(jQuery(this).parents(".content-inset-wrap"));
    nLi.appendTo(nUl);
  
    nLi.append(this);
  
  })
  </code></pre>
  
  <p>});</p>
  
  <p>Any help very much appreciated!</p>
  
  <p>Thanks.</p>