1

I am not sure the title of my question specifies correctly what I am looking for, but several newswebsites are using some sort of "See Also" or "Don't Miss" sections which appear between the first and second paragraphs on their articles and links to a related article. In my opinion it's a great feature as it can keep visitors longer on the website.

I have been looking to implement this on my D7 website but there seems to be no easy way to add a custom field or something in node body text. Any help would be appreciated

Here are some examples:

1 Answer 1

1

Really the best way to do this is with multiple fields. Rather than injecting your related content block in the middle of your body, have 3 separate fields.

1) A teaser field (contains the first paragraph)

2) Related content field (This would likely be an entity reference field. You can render the referenced node with a chosen display mode.)

3) Body field (contains the rest of the post)

The other way to do this would be by dynamically splitting your content (probably with regex) and inserting your other field in the middle. Personally, I wouldn't recommend this second option.

5
  • Thanks for the quick reply. I have been thinking about the first option and it would be the easiest way to be implemented. Although, we have a lot of older articles which get quite some visitors and this would result with the related content field to be on top. Also, the related content field should be a view-field or something, with arguments to relate another node to the current ?
    – Apoc
    Jan 23, 2017 at 23:18
  • Updated my answer to make it a bit more clear. I also added a bit of detail on the related content field. If you need more details than this, let me know and I'll write up something a bit more in-depth.
    – lukedekker
    Jan 23, 2017 at 23:22
  • I am aware of the functionalities of entity reference field. I wouldn't render the complete node, but just the title of the related node. Why would you not recommend to use the option to dynamically split the content?
    – Apoc
    Jan 23, 2017 at 23:30
  • Generally, it isn't recommended to create functionality that depends on the user not being dumb. :) But more importantly, embedding the reference would require you to manually render it, and output it in the middle of body string. String manipulation of this kind is also vulnerable to changes down the road. I'm not saying never do string manipulation, just make sure that that is the absolute right way to do it.
    – lukedekker
    Jan 23, 2017 at 23:42
  • I see.. I will give it a shot with the multiple fields, when discussed with the editors. Thanks for your answer!
    – Apoc
    Jan 23, 2017 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.