Jump to content
UBot Underground

Paragraphs in WP


Recommended Posts

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

Link to post
Share on other sites

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")
Link to post
Share on other sites

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?

Link to post
Share on other sites

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.

Link to post
Share on other sites

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!

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...