How can I related post in mid of a post?

As you have seen in wordpress that we can insert post in between any post by using some plugin. I’m looking for a way to do that in ghost.
Is it possible to do that?

Yes, it is possible to add related posts inside the post content using javascript. Just you have to use a wrapper div where you will push the related posts content.

  • make related posts in the post page
  • Use javascript / jQuery to take the content
  • Use a whapper html in the post where you want to show

If you feel free, contact with me. I will help you.

Thanks

1 Like

You could also use the bookmark card to link to another post.

3 Likes

That would be a manual work each time I make a new post.
I’ve already made related post useing {{#get}} at the end of post.
I think as @ ENAMUL_HAQUE said, grabbing first or 2nd

tag then appending

with related post gonna be a perfect solution.
Do you think it’s the correct way to do it?

Hi @Prashant_Verma,
You can easily do it. Just split your post content from first 2 paragraph then add your related posts. It will be easy for you.

// inserting related post in the content
var postContent = document.querySelectorAll('.post-content p'),
relatedPostWrap = document.querySelector('.related-post').innerHTML,

relatedPostElement = document.createElement('div')
relatedPostElement.classList.add('related-post-inside-post')

relatedPostElement.innerHTML = relatedPostWrap

postContent[3].after(relatedPostElement)

Instruction

  • Take all p elements inside the post var postContent = document.querySelectorAll('.post-content p')
  • Related posts inner content document.querySelector('.related-post').innerHTML
  • Added the related posts element after specific p tag postContent[3].after(relatedPostElement)
1 Like

Thanks for this code. I will be implementing it very soon.