Sep 10, 20245:47 AM - edited Sep 10, 20245:50 AM
Top Contributor
Remove Link from Blog Authors Name
SOLVE
Hi, is there a way to remove the link from a blog authors name if they have only written one blog? Currently all blog authors names link to a page deicated to all the posts they have written.
Is there a way to rewrite the above code so that it checks to see how many blogs the author has written? Or is there a way in the Hubspot blog author table to added a checkbox to turn this feature on or off depending on the number of blogs an author has written?
That's an interesting request! I haven't done this myself but it should be possible if you use blog_recent_author_posts and check the length of the returned value.
Try something like this:
{% set author_posts = blog_recent_author_posts("default", content.blog_post_author.slug, 5) %}
{% if author_posts|length > 1 %}
<h4>Written by <a class="author-link" href="{{ group.absolute_url }}/author/{{ content.blog_post_author.slug }}">{{ content.blog_post_author.display_name }}</a></h4>
{% else %}
<h4>Written by {{ content.blog_post_author.display_name }}</h4>
{% endif %}
The code above stores the 5 most recent articles for the author of the blog under the author_posts variable and then checks its length to decide if it should show a link or not.
If the author has more than 1 article, it will show the link, otherwise it won't.
Let me know if that helps! 🙂
Did my answer help you? Mark it as a solution ✅
Do you need help with your site? Book time with me:
{% set author_posts = blog_recent_author_posts("default", content.blog_post_author.slug, 200) %}
{% if author_posts > 1 %}
<h4>Written by <a class="author-link" href="{{ group.absolute_url }}/author/{{ content.blog_post_author.slug }}">{{ content.blog_post_author.display_name }}</a></h4>
{% else %}
<h4>Written by {{ content.blog_post_author.display_name }} </h4>
{% endif %}
I'd recommend to put this code inside a custom module since it will give you more flexibility and (a bit better usability) in the long run. It would also allow you to add a lot of modifcations for later use.
For instance:
You could add a blog select option if you have several blogs (or planning to have several ones)
You could add a number field to manually change the amount per blog listing. For instace you'd like to check for more than 1 post in "BLOG A" but for more than 5 posts in "BLOG B"...
{% set author_posts = blog_recent_author_posts("default", content.blog_post_author.slug, 200) %}
{% if author_posts > 1 %}
<h4>Written by <a class="author-link" href="{{ group.absolute_url }}/author/{{ content.blog_post_author.slug }}">{{ content.blog_post_author.display_name }}</a></h4>
{% else %}
<h4>Written by {{ content.blog_post_author.display_name }} </h4>
{% endif %}
I'd recommend to put this code inside a custom module since it will give you more flexibility and (a bit better usability) in the long run. It would also allow you to add a lot of modifcations for later use.
For instance:
You could add a blog select option if you have several blogs (or planning to have several ones)
You could add a number field to manually change the amount per blog listing. For instace you'd like to check for more than 1 post in "BLOG A" but for more than 5 posts in "BLOG B"...
That's an interesting request! I haven't done this myself but it should be possible if you use blog_recent_author_posts and check the length of the returned value.
Try something like this:
{% set author_posts = blog_recent_author_posts("default", content.blog_post_author.slug, 5) %}
{% if author_posts|length > 1 %}
<h4>Written by <a class="author-link" href="{{ group.absolute_url }}/author/{{ content.blog_post_author.slug }}">{{ content.blog_post_author.display_name }}</a></h4>
{% else %}
<h4>Written by {{ content.blog_post_author.display_name }}</h4>
{% endif %}
The code above stores the 5 most recent articles for the author of the blog under the author_posts variable and then checks its length to decide if it should show a link or not.
If the author has more than 1 article, it will show the link, otherwise it won't.
Let me know if that helps! 🙂
Did my answer help you? Mark it as a solution ✅
Do you need help with your site? Book time with me:
Thank you for taking the time to look into this for me. I have aded the code into my html but am getting an error:
The error console isn't much help:
If I remove this part of the code the error resolves:
{% set author_posts = blog_recent_author_posts("default", content.blog_post_author.slug, 200) %}
Not sure what to do as the error isn't giving me much to go on. Ihave tried placing this line of code above the other code. I have also placed it at the start of the HTML.
Hey @Woodsy! Thanks for your post. Let's invite some of our experts to see if they have any suggestions!
@Jnix284, @Anton, @DaniellePeters -- do any of you know how we might remove the link from the author name on select blog posts? Ideally, we could make this dynamic based on the total blog posts they've written. All workarounds are welcome! Thanks 😊
Best, Kennedy
Did you know that the Community is available in other languages? Join regional conversations by changing your language settings !