php - Wordpress: Moving inline images to Featured Galleries -


This is my position:

I am giving a new look to an existing Wordpress site.

The new design separates all posts from the actual post content and puts it in one.

Currently, you have specific inline images in the post content in each post.

Is it also possible to remove all inline images from the post content and to create a featured gallery with those pictures for each post?

In the past, I have achieved something like before, the image in the post content, and it was set as standard painted image, but I have to do with this dilemma. $ Already_has_thumb = is_post_ thumbnail ($ post-> ID); If (! $ Already_has_thumb) {$ attached_image = get_children ("post_parent = $ post-> ID and post_type = attachment & amp; post_mime_type = image & amp; numberposts = 1"); If ($ enclosed_image) {foreach ($ attached_image $ attachment_id = & gt; $ attachment) {set_post_thumbnail ($ post-> ID, $ attachment_id); }}}} // end function add_action ('the_post', 'wpforce_featured'); Add_action ('save_post', 'wpforce_featured'); Add_action ('draft_to_publish', 'wpforce_featured'); Add_action ('new_to_publish', 'wpforce_featured'); Add_action ('pending_to_publish', 'wpforce_featured'); Add_action ('future_to_publish', 'wpforce_featured');

Actually the method I used to create a script once All the inline images of the post I ran to move, to this kind of featured gallery:

  // While loop on each post (is_posts ()): the_post (); // Get images related to post $ Imageids = array (); $ Images = get_attached_media ('image', $ post-> ID); Foreign Currency ($ Images $ Image) {$ imageids [] = $ image- & gt; Id; } $ Comma_separated = implode (",", $ imageids); // if they ($ post- & gt; post_type == 'amendment') {return;} if (get_post_meta ($ post-> ID) save them in featured gallery (this information is featured gallery plugin Dig into the source code of), 'Fg_perm_metadata', FALSE) {update_post_meta ($ post-> ID, 'fg_perm_metadata', $ comma_separated); } Other {add_post_meta ($ post-> ID, 'fg_perm_metadata', $ comma_separated); } If (! $ Comma_sapated) delete_post_meta ($ post-> ID, 'fg_perm_metadata'); Endwhile; // reset query wp_reset_query ();  

Then, I created a function that removes all the images in the posted content, which I put into the function. Php:

  function remove_images ($ content) {$ Content = preg_replace ('{& lt; a (. *?) (Wp-att | wp-content \ / upload) [^ Gt;] & gt; & lt; img} ',' {wp-image- [0- 9] * "/> gt; & lt; / a & gt;}, array ('& lt; img' , '/' & Gt; '), $ Content); $ Content = preg_replace (' / & lt; img (. *) & Gt; / i ',' ', $ content, 1); $ refund;} Add_filter ('the_content', 'remove_images');  

Removes the link around the first preg_replace images, removes the second image.

< / Div>

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -