-
edirik
Hi,
I want to add related articles in the middle and at the end of the post.
So I am adding a query element inside Single Post template, my questions as follow:
1) I want the query not to show the existing post. For example, if the post is about “Benefits of Apples”, then I would see “benefits of banana” and “benefits of buying a car” but it would be weird to see “Benefits of Apples” again. How can I exclude that?
2) It is easy to add the related article to the end but is there a way to add an element e.g., Query for related posts inside “Dynamic Content”? For example, half way of each post I should be able to show related news.
3) In terms of showing the related news, I thought of randomly showing articles from the last 7 days. Do you have any best practice in terms of showing those articles without impact core web vitals etc?
Thanks,
-
Hi there,
1. To exclude the current post requires GB Pro. If you have GB Pro, you can add an exlude posts parameter, and select current post.
2. There is NO hook in the content area, you will need to create custom hook via the
the_content()filter.
For example, this post teaches how to add custom hook after 1st paragraph:https://generatepress.com/forums/topic/element-after-first-paragraph/and this code is an adaptation of the previous one, by creating custom hook after the sixth paragraph: https://generatepress.com/forums/topic/show-element-after-specific-paragraph/#post-2067989
3. Random order requires more resources than the other orders, so it’s your choice to use or not use it.
-
edirik
Hi,
To elaborate on the 3. Point, do you mean that it is not a good idea to ask the Query bring content randomly? What do you mean by resources e.g., would it impact Page Speed or Core Web Vitals?
Thanks
-
What do you mean by resources e.g., would it impact Page Speed or Core Web Vitals?
Yes, that’s what I mean. But if you only have 1 query that is pulling posts randomly, then it’s likely ok.
- You must be logged in to reply to this topic.