AaronForce1 / cartopress

CartoDB Plugin for Wordpress
6 stars 2 forks source link

Display map into single post #2

Open erapisardi opened 8 years ago

erapisardi commented 8 years ago

Hi, Is there a way to view the map in each single post displaying only the post geolocation? thanks

hallisey commented 8 years ago

Hi Elena, thanks for the question. This is more a CartoDB question than one about the plugin itself. But since you are the first person to leave a question you get special treatment ;)

You can create custom views using CartoDB by modifying the SQL query. In order to show a point for a single post you can create a query such as

SELECT * FROM dataset_name WHERE cp_post_id = '23'; which would show only the point for Post ID # 23

If you would like to display a map on each post where you have location information and show only that point you are going to have to use the CartoDB.js API and, using Javascript/Leaflet, build a map into your post or page template where the sublayer SQL query reflects the post ID for that post.

Here is a CartoDB tutorial for creating a map with the CartoDB.js API https://docs.cartodb.com/tutorials/create_map_cartodbjs/. Pay close attention to the section called 'Adding Client Side SQL and CartoCSS' as it describes creating a custom sublayer based on an SQL query. Essentially what you need to do is create a JS variable that is the post ID for the current post and you can modify the SQL query above using that variable. So if you are following the example in the tutorial link above your SQL query might look like something like this:

var thepostid = "<?php echo $post_id ?>"; var subLayerOptions = { sql: "SELECT * FROM dataset_name where cp_post_id = '" + thepostid + "'" }

Make sure that you replace dataset_name with what your dataset name is of course.

Anyway, I hope that helps. The plugin mostly functions to get and sync WordPress data with CartoDB so right now you have to use the CartoDB publishing tools to create maps. I think that CartoDB has some publishing options offered via Jetpack, but I have to admit that I have never used it and not very familiar with it, but it could be another alternative. Aaron and I are hoping to add some shortcodes in the future for quick map publishing, but we probably wont get to it until later this summer :/

Best, Troy

erapisardi commented 8 years ago

Dear Troy, thank you for the instructions. I will try to follow them.

Hope a shortcode will come soon!

thanks a lot

elena

Elena Rapisardi, PhD mobile +39.3391820158 skype elenis1517


Stampate questa mail solo se necessario. Non consumiamo carta inutilmente. Please don't print this email unless you really need to.

On 19 May 2016 at 03:25, T. Andrew Hallisey notifications@github.com wrote:

Hi Elena, thanks for the question. You can create custom views using CartoDB by modifying the SQL query. In order to show a point for a single post you can create a query such as

SELECT * FROM dataset_name WHERE cp_post_id = '23'; which would show only the point for Post ID # 23

If you would like to display a map on each post where you have location information and show only that point you are going to have to use the CartoDB.js API and, using Javascript/Leaflet, build a map into your post or page template where the sublayer SQL query reflects the post ID for that post. Here is a CartoDB tutorial for creating a map with the CartoDB.js API https://docs.cartodb.com/tutorials/create_map_cartodbjs/. Pay close attention to the section called 'Adding Client Side SQL and CartoCSS' as it describes creating a custom sublayer based on an SQL query. Essentially what you need to do is create a JS variable that is the post ID for the current post and you can modify the SQL query above using that variable. So if you are following the example in the tutorial link above your SQL query might look like something like this:

var thepostid = "<?php echo $post_id ?>"; var subLayerOptions = { sql: "SELECT * FROM dataset_name where cp_post_id = '" + thepostid + "'" }

Anyway, I hope that helps. The plugin mostly functions to get and sync WordPress data with CartoDB so right now you have to use the CartoDB publishing tools to create maps. Aaron and I are hoping to add some shortcodes in the future for quick map publishing, but we probably wont get to it until later this summer :/

Best, Troy

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/MasterBaideme1021/cartopress/issues/2#issuecomment-220204072

hallisey commented 8 years ago

Hi Elena,

Hope that works out for you. Using a short code would still be a very manual process. I think it is better for automation to build a map into your template anyway.

If you don't mind the manual process for each post, you can create custom views directly in CartoDB using the SQL editor (using SELECT * FROM [yourdataset_name] WHERE cp_post_id = '[yourpostID]'; and then use the Embed code in the publishing options.