CMS Development

Roworo
Participante

Posts ID

Hi, i'm brand new in hubl, and i'm having trouble understanding how does ID in posts works. I'm working over a web page that was alredy done and I can't find the posts they did, they are using the post id to iterate on it and get some information from it. How do i get the post ID? And most important, if I have a post ID can I find that post and modify it?

 

This is an example of what they are doing:

 

{% set blog = html_lang == 'es' ? '5882279228':'5892336346' %}
{% set contents = blog_recent_posts(blog, 22) %}
{% for content in contents|sort(false, false, 'updated') %}
<a href="{{content.absolute_url}}" class="item_destino_destacado w-inline-block item_destino" data-item="{{content.widgets.inicial.body.value}}" data-attr='{{content.name}}'>
<div class="borde_img">
<div class="imagen_principal_destino img_over" style="background-image: url({{content.featured_image}})" data-src="{{content.featured_image}}"></div>
</div>
{#{{content.featured_image}}#}
<div class="nombre_destino-s">
<div class="nombre_destino_ptions">{{content.name}}</div>
<div class="linea_horizontal">
<div class="linea_horizontal_negra"></div>
</div>
<div class="descripcion_destino">{{ content.post_list_content|truncatehtml(100, "...", false) }}</div>
<div class="more_details_destino">{{ html_lang == 'es' ? 'Más detalles' : 'More details' }}</div>
</div>
</a>
{% endfor %}

 

Tnks

0 Me gusta
2 Respuestas 2
lscanlan
Exmiembro de HubSpot
Exmiembro de HubSpot

Posts ID

Hi @Roworo,

 

Welcome. If you're new to HubL, I'd strongly recommend familiarizing yourself with the Developer Info page, which we have documented here: https://designers.hubspot.com/docs/hubl/how-to-use-developer-info-on-cms-pages. It will show you everything available on a page through HubL and how to access those values.

 

As for how to find a content ID, probably the easiest way to find that is in the URL for it in-app. So for example if you click into the details page for a blog post, that URL might look like this: https://app.hubspot.com/content-detail/437004/blog-post/6984328219/performance. The first number is the account ID. The second number (in this example 6984328219) is the ID for this blog post. You can also see that same ID in the editor URL for that blog post: https://app.hubspot.com/blog/437004/edit-beta/6984328219/content. The same would be true for an email or website/landing page.

 

But your example code is actually a little different than finding blog post IDs. It looks like it's set up to use the blog_recent_posts() function: https://designers.hubspot.com/en/docs/hubl/hubl-supported-functions#blog-recent-posts, which will create a list of the most recently published posts from a specified blog. The function has 2 parameters: the 1st is the ID for the blog to pull posts from, and the 2nd is the number of posts to pull in. On the first line, there's a variable "blog" being set with the ternary operator:

 

{% set blog = html_lang == 'es' ? '5882279228':'5892336346' %}

So if html_lang is equal to "es", the blog ID will be set to 5882279228. Otherwise it will be set to 5892336346. And then the posts that are pulled in are iterated on and printed into the HTML.

 

The blog ID can also be found in the in-app URL for the blog's dashboard. So when you navigate to a blog's dashboard, you'll have a URL like https://app.hubspot.com/website/437004/blog/posts?author=all&blog=6983986317&campaign=all&columnA=cr.... The blog's ID in this example is 6983986317. Or alternatively if you were looking at the Developer Info page for your blog, you could access the blog's ID with {{ content_group.id }} .

 

As for modifying a post by its ID, are you trying to update the live content for the post? Or just manipulate some of the post's data on a page? If the former, you could plug the ID into the editor URL and edit it in-app. Or you could use our CMS Blog Post API: https://developers.hubspot.com/docs/methods/blogv2/put_blog_posts_blog_post_id. If you're trying to manipulate some of the data on a separate page, that's possible also, so let me know what you're trying to do in that case.

 

Let me know if this helps or if you have any questions about it.

 

Leland Scanlan

HubSpot Developer Support
Roworo
Participante

Posts ID

Thanks a lot, it worked

0 Me gusta