Change number of search results per page?

SOLVE
Highlighted
Regular Contributor

I've cloned the search results module to repurpose, all is fine I only have one last little tweak I can't seem to figure out.

 

I have a 3 column results page but the search result pages pulll 10 results per page. This is annoyign is I don't have an even 3x3 grid. I'd like to reduce the results pp to 9 but can't see how I would do this.

 

At first I thought changing the

 

function getLimit() {
  return parseInt(params.get('limit'));
}

To have a static integer would work but didn't seem to have an effect.

1 Accepted solution

Accepted Solutions
HubSpot Moderator

Hi @benji_thecroc,

 

I believe you can do this by just adjusting the search URL. There's a function httpRequest() that sets a variable:

 

var SEARCH_URL = "/_hcms/search?"

 

The CMS site search works basically the same way as the http API, documented here: https://developers.hubspot.com/docs/methods/content/search-for-content. There's an optional query parameter for limit. So if you wanted to continue searching only the current domain using that default SEARCH_URL variable, you could just add the limit parameter in the query string. I think you'd end up with this:

 

var SEARCH_URL = "/_hcms/search?limit=9&"

 

On the other hand if you wanted to search all domains in your portal, you could do something like this:

 

var SEARCH_URL = "https://api.hubapi.com/contentsearch/v2/search?portalId=YOUR-HUB-ID-HERE&limit=9&",

 

Let me know if that'll work for you. But in testing I think this should work for you.

 

 - Leland

Leland Scanlan

HubSpot Developer Support
2 Replies 2
HubSpot Moderator

Hi @benji_thecroc,

 

I believe you can do this by just adjusting the search URL. There's a function httpRequest() that sets a variable:

 

var SEARCH_URL = "/_hcms/search?"

 

The CMS site search works basically the same way as the http API, documented here: https://developers.hubspot.com/docs/methods/content/search-for-content. There's an optional query parameter for limit. So if you wanted to continue searching only the current domain using that default SEARCH_URL variable, you could just add the limit parameter in the query string. I think you'd end up with this:

 

var SEARCH_URL = "/_hcms/search?limit=9&"

 

On the other hand if you wanted to search all domains in your portal, you could do something like this:

 

var SEARCH_URL = "https://api.hubapi.com/contentsearch/v2/search?portalId=YOUR-HUB-ID-HERE&limit=9&",

 

Let me know if that'll work for you. But in testing I think this should work for you.

 

 - Leland

Leland Scanlan

HubSpot Developer Support
New Contributor

This worked for me, Leland. Thanks for posting.

 

I came to make the same suggestion as OP and still think the product would benefit from a more accessible setting.

Reply
0 Upvotes