CMS Development

Paresh_Bhavsar
Membre

Multiple authors for blog

Résolue

We have a client with a requirement to be able to associate multiple authors to a single blog post. I know this is not available in Hubspot so we created a custom module to add authors to each blog and it works fine - we are 99% there. 

However, right now a user has to manuall enter name and image of every author for every blog. 

Paresh_Bhavsar_0-1664778434067.png

DESIRED 
What we want is to have the drop-down list of authors available for user to select from. All users in the list should come from here 

Paresh_Bhavsar_1-1664778536435.png


So, user enter all Authors information in deafult screen in Hubspot and we pull these values in a drop-down in a custom module to add additional authors. 

Can anyone help with what field name vaule of code we can use to fetch the drop-down? 

Thanks 
Paresh Bhavsar 
Bold Dialogue 

 

1 Solution acceptée
BarryGrennan
Solution
Contributeur de premier rang

Multiple authors for blog

Résolue

I did find my old code in the end, I wasn't far off

{# SECOND AUTHOR #}
			{% set auth_selector = [] %}
			{% set my_authors = blog_authors('default', 250) %}
			 {% for item in my_authors %}
           {% do auth_selector.append( [item, item.full_name] ) %}
              {% endfor %}
			  
			  {% choice "second_auth_selector" label="Second Author",  choices={{auth_selector}}, export_to_template_context=True %}
       {% set second = content.widgets.second_auth_selector.body.value %}
	  {% if second.name  %}
	    <div id="second_author" class="author">
		 {% if second.avatar %}
          <div class="author-image" style="background-image:url({{ second.avatar }});"></div>
	 	    {% else %}
   <div class="image-placeholder"></div>
      {% endif %}
        <div class="author-details">
	  <div class="author-name">{{ second.name }}</div>
	  <div class="author-bio">
          {% if  second.bio is containing auth_needle %}
      {{ second.bio|regex_replace("@.*$", "")|regex_replace("_", " ") }} @ {{ second.bio|regex_replace("^[^@]*@", " ")|regex_replace("_", " ") }}
      {% else %}
      {{ second.bio }}
      {% endif %}
          </div>
	  <div class="date-created">{{ content.publish_date|datetimeformat('%e %b %Y') }} </div>
		  </div>
		  </div>
		  {% endif %}

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact

 

 

 

Voir la solution dans l'envoi d'origine

7 Réponses
BarryGrennan
Solution
Contributeur de premier rang

Multiple authors for blog

Résolue

I did find my old code in the end, I wasn't far off

{# SECOND AUTHOR #}
			{% set auth_selector = [] %}
			{% set my_authors = blog_authors('default', 250) %}
			 {% for item in my_authors %}
           {% do auth_selector.append( [item, item.full_name] ) %}
              {% endfor %}
			  
			  {% choice "second_auth_selector" label="Second Author",  choices={{auth_selector}}, export_to_template_context=True %}
       {% set second = content.widgets.second_auth_selector.body.value %}
	  {% if second.name  %}
	    <div id="second_author" class="author">
		 {% if second.avatar %}
          <div class="author-image" style="background-image:url({{ second.avatar }});"></div>
	 	    {% else %}
   <div class="image-placeholder"></div>
      {% endif %}
        <div class="author-details">
	  <div class="author-name">{{ second.name }}</div>
	  <div class="author-bio">
          {% if  second.bio is containing auth_needle %}
      {{ second.bio|regex_replace("@.*$", "")|regex_replace("_", " ") }} @ {{ second.bio|regex_replace("^[^@]*@", " ")|regex_replace("_", " ") }}
      {% else %}
      {{ second.bio }}
      {% endif %}
          </div>
	  <div class="date-created">{{ content.publish_date|datetimeformat('%e %b %Y') }} </div>
		  </div>
		  </div>
		  {% endif %}

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact

 

 

 

TheLexicon
Membre

Multiple authors for blog

Résolue

@BarryGrennan are you able to show where you replace info at? Not an expert with HTML but not sure what to do with your code and where to put it. 

0 Votes
CD20623
Participant

Multiple authors for blog

Résolue

Hi, 

How can I implement the second author slug (url)? I was able to work with your code to get the second author on our blog template, but I'm having a bit of an issue with grabbing the second author url. The 1st author is using this:

<a href="{{ group.absolute_url }}/author/{{ content.blog_post_author.slug }}" alt="">{{ second.name }}</a> Any help you can provide for me to pull the second author slug would be great. Thank you

0 Votes
Paresh_Bhavsar
Membre

Multiple authors for blog

Résolue
Thank you Barry. Will try this and let you know.
0 Votes
BarryGrennan
Contributeur de premier rang

Multiple authors for blog

Résolue

I did something like this for a client once. Unfortunately they're not on hubspot anmore and I don't have the code saved anywhere.

 

But for author one I'd pull it in in the standard way.

 

Then for author two, I think you can do something like use a choice tag that you fill using the recent authors tag.

You'll definitely need to fiddle around with this but it's something like 

// Empty Array
{% set authors_list = [] %}

// Get Authors
{% set my_authors = blog_authors("default", 250) %}

// Add Authors to array
{% for author in my_authors %}
{% do authors_list.append(author) %}
{% endfor %}

//Push authors into choice field
{% choice "second_author" label="Choose second author", value=authors_list %}

// Output second author
{{ second_author }}

 

Again, that's entirely off the top of my sleepless head so you'll no doubt need to fiddle with it but it's a start.
Maybe you can get {{second_author.url}} etc. from that, maybe not, maybe you need to expand what you'd adding to the array to get that.


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact

 

 

0 Votes
LeeBartelme
HubSpot Employee
HubSpot Employee

Multiple authors for blog

Résolue

I don't think you'll be able to do it the route you are going. If I was in your shoes, the route I would go would be to create a HubDB table with the data (name, title, image etc) about each author. Then in my module, for the field type I'd make it a HubDB row and make it use the repeater functionality.

 

When you drop that module on a post you can then select one or more authors, and use them in your module similar to how you are now.

ChehakWadhdwa
Membre | Partenaire solutions Diamond
Membre | Partenaire solutions Diamond

Multiple authors for blog

Résolue

Hey @Paresh_Bhavsar

 

In case of Author you can retrieve only single author as author is a single selection element , multiple selection is possible only for the tags not for the author, so you can not show multiple author in dropdown as how you want.

 

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

0 Votes