CMS Development

DM2
Member

Creating a custom list of selected blog posts

SOLVE

Hi  

 

I am creating a 'related blog posts' area to sit on post pages.

 

I want to be able to select 3 other blog posts on a case by case basis to sit in this area...I can see how to pull and display the most recent 3 posts in the blog but I want to be able to select posts randomly.

 

I'm displaying using:

 

{% set contents = blog_recent_tag_posts('default', 3) %}

{% for content in contents %} 

My markup to display the posts..

{% endfor %}

so I guess I need a drop down list in the custom module that accesses blog posts and then to pull an id in to the above contents statement, 3 times or in an array...?

 

Would be grateful for any pointers here. Thanks!

0 Upvotes
1 Accepted solution
DM2
Solution
Member

Creating a custom list of selected blog posts

SOLVE

Thanks! that works well...I only wanted one article in the end so I used content_by_id

 

Is there a way of giving the content editor a drop down list to select blog article by it's name/title? As opposed to them having to cut and paste an ID - I could only seem to get this via the url for the post? 

View solution in original post

0 Upvotes
6 Replies 6
stefen
Key Advisor | Partner
Key Advisor | Partner

Creating a custom list of selected blog posts

SOLVE

@DM2 there are a couple new HubL functions that should help with this called "content_by_id" and "content_by_ids": https://designers.hubspot.com/docs/hubl/functions#content-by-ids

 

Basically, you just need the user to select the three posts via a custom module page selector or have them copy and paste the post ID into a text field and you could then output those three posts on the page with either of these functions.

Stefen Phelps, Community Champion, Kelp Web Developer
DM2
Solution
Member

Creating a custom list of selected blog posts

SOLVE

Thanks! that works well...I only wanted one article in the end so I used content_by_id

 

Is there a way of giving the content editor a drop down list to select blog article by it's name/title? As opposed to them having to cut and paste an ID - I could only seem to get this via the url for the post? 

0 Upvotes
stefen
Key Advisor | Partner
Key Advisor | Partner

Creating a custom list of selected blog posts

SOLVE

@DM2 in custom modules, yes. The "Page" selector field is what you want.

Stefen Phelps, Community Champion, Kelp Web Developer
0 Upvotes
DM2
Member

Creating a custom list of selected blog posts

SOLVE

oh great Stefen thanks,  yes that's a bit more user friendly!!!

 

If I may ask one final question related to this...this custom module is a snippet in the Blog Post Listing Template ('Blog content' code view). It needs to be here because it is embedded in between other posts.

 

This means when the end content editor needs to alter it they have to go directly to the module in Design Manager which isn't very user friendly for non tech, has code and settings to dodge etc.

 

Is there any workaround for this to enable the user to launch and edit module in a more user friendly fashion (rather as you you do in page view)?

Hope that makes sense as a question...

 

0 Upvotes
stefen
Key Advisor | Partner
Key Advisor | Partner

Creating a custom list of selected blog posts

SOLVE

@DM2 Probably the best way to solve that is using a global module and using the global module editor since you can't edit blog listing pages directly via the page editor.

Stefen Phelps, Community Champion, Kelp Web Developer
0 Upvotes
DM2
Member

Creating a custom list of selected blog posts

SOLVE

Just for any one following this thread in the future re-creating the module as a global (it was local before) worked and allowed a better editing experience for the end user in the global module editor (as opposed to design manager).

 

Thanks to Stefan again.

0 Upvotes