Question

I've got a site where users can create groups (we call them games)

www.ongoingworlds.com/games/270/ www.ongoingworlds.com/games/287/ etc

Each of these games has it's own user-generated content. I want to use a Google custom search for each game. But I can't see an easy way to amend the embed code to add a dynamic path, and I don't want to have to register multiple (hundreds) of GCSEs separately to get an embed code for each.

What would be the best way of allowing each of these URLs (above) to have their own GCSE?

Was it helpful?

Solution

You can search subparts of your site by using a combination of site: operator and webSearchQueryAddition parameter on gcse element.

webSearchQueryAddition appends additional search term to your user's query. If for each of the "games" you change the webSearchQueryAddition to point to the "game" base url, the search results will be matching that url. You can inject that parameter programmatically with e.g. javascript, for each of the "games".

Documentation is here: https://developers.google.com/custom-search/docs/element#supported_attributes

And here is working example: http://jsfiddle.net/t2s5M/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top