ugakebet 4 Posted May 30, 2013 Report Share Posted May 30, 2013 Im trying to insert pictures after paragraphs in Wordpress. I've got the pictures not the problem is how do I insert them after a paragraph. I can't seem to get the regex to find out when a paragraph is there.... Insert new line and then insert image Quote Link to post Share on other sites
UBotDev 276 Posted May 30, 2013 Report Share Posted May 30, 2013 You can solve that by use of "$find index" and "$substring" functions. First you locate the end of first paragraph, and then you just call parts of HTML with "$substring" Here is an example: set(#TEXT, "<p>test</p> <p>test</p> <p>test</p>", "Global") set(#PAR First End, $find index(#TEXT, "</p>"), "Global") set(#TEXT Final, "{$substring(#TEXT, 0, $add(#PAR First End, 4))}<img scr=\"image.jpg\"/>{$substring(#TEXT, $add(#PAR First End, 5), $subtract($subtract($subtract($text length(#TEXT), 1), #PAR First End), 4))}", "Global") Quote Link to post Share on other sites
ugakebet 4 Posted May 30, 2013 Author Report Share Posted May 30, 2013 Well, the problem is in the first line which you wrote. I do not know the paragraphs (each post has different paras). When in text view, it doesnt show me the <p> tags so i cant use the 'set' option like you mentioned. What else? Quote Link to post Share on other sites
UBotDev 276 Posted May 30, 2013 Report Share Posted May 30, 2013 Switch to HTML view? Quote Link to post Share on other sites
ugakebet 4 Posted May 30, 2013 Author Report Share Posted May 30, 2013 Ummm... I'm already in that (and now its called text mode -- which shows up in ubot as just "content") Quote Link to post Share on other sites
UBotDev 276 Posted May 30, 2013 Report Share Posted May 30, 2013 Oh, I'm sorry, I forgot about that. Then replace "</p>" with "$new line" in the code above, and I think that should do the trick. Still, it could happen that paragraphs are shown on some old blogs, so you may want to check for that first, and if it doesn't exist, use new line instead. Quote Link to post Share on other sites
VaultBoss 310 Posted May 31, 2013 Report Share Posted May 31, 2013 The text view in WP doesn't show the paragraphs per se, as in HTML, unfortunately... You can only see them if you preview the page in the browser. Instead of that, WP inserts an extra row of white space between actual paragraphs in text view (probably adds the <p> tags when it pulls the text from DB at rendering later, when a client browser requests the content.) You would need to take the text content and add it to a list (use $add list to list) with the $new line separator. That is the easiest way to automate the text split into paragraphs, so to speak... Then you can insert your image wherever you want, by appending at the end of the list item you want. And then transform the list into text again and paste back into WP. Hope this idea helps you... Cheers! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.