• I needed to display the map in different places on various pages, so I created a shortcode tag to indicate where it is displayed. The code that sits in the theme’s functions.php is:

    function pronamictag_func($atts) {
    	extract(shortcode_atts(
    		array(
    			'width' => 500,
    			'height' => 300,
    		), $atts
    	));
    
    	return pronamic_google_maps(array(
    		'width' => $width,
    		'height' => $height,
    		'echo' => false,
    	));
    }
    add_shortcode('pronamic', 'pronamictag_func');

    With this I can insert a shortcode tag anywhere in the content to display the map, like this:

    [pronamic]

    or

    [pronamic width=600 height=200]

    It would be nice if the width could be expressed as a percentage, but it is always interpreted as pixels.

    — Jason

Viewing 15 replies - 1 through 15 (of 17 total)
  • This is great! Thank you for sharing!! Would it be possible to add a parameter for a static map?

    Thread Starter Jason Judge

    (@judgej)

    It probably would, and I can see how useful it would be (the relationship of one map per page or post that the plugin imposes may be useful in some circumstances, but other times multiple maps on a page would be very handy.

    It would probably need some changes in the core plugin though, because only the width and height are accepted as parameters in the pronamic_google_maps() function.

    Another approach could be to put maps into hidden posts, and pass the post ID as a parameter. That way there is not too much work involved having to extend the parameters to include everything you may possibly need in a map (title, name, coords, addresss…). A post type called “maps” would work, though making post types that WordPress does not automatically index and make available to the world is a pain.

    Anyway, there are some ideas, so hopefully they will land on the right lap for some implementation πŸ˜‰

    Plugin Author Remco Tolsma

    (@remcotolsma)

    @judgej #post-2189771
    In version 2.0 the shortcode [google-maps] will be available.

    The plugin is using the default embed width and height wich you can configure in WordPress (Settings Β» Media).

    There are ofcourse attributes available:

    [google-maps width=300 height=200 static=true label=M]

    @judgej #post-2211892
    You could also use the Pronamic Google Maps widget to add maps that are not related to posts.

    @judgej: Thanks for sharing your solution with us.

    @remco Tolsma: Thanks for the update! Is there an expected date of release for v2.0?

    Plugin Author Remco Tolsma

    (@remcotolsma)

    @flick We will launch version 2.0 this week.

    Thanks Remco πŸ™‚

    @judgej: I copied your code in the theme’s functions php and I got:

    Parse error: syntax error, unexpected T_STRING in /home1/paginapa/public_html/armariodemaria/wp-content/themes/Suerte-1.1/includes/functions.php on line 144

    πŸ™ ?? can you or somebody else tell me what’s going on, where’s the problem

    thanx

    Aldin

    Thread Starter Jason Judge

    (@judgej)

    There is a syntax error on line 144 of includes/functions.php That is where you need to look first.

    yeah, I understood that, but the only thing I did was paste your code there, so there must be an error in the code?

    Thread Starter Jason Judge

    (@judgej)

    There is certainly an error in the code that was pasted, on line 144. We can’t tell you what that could be, because we can’t see line 144. We have no idea what line 144 is. Perhaps with some clues, we could help.

    well, now I just get the error message, can’t even get into my dashboard πŸ™
    is there something I can do beside reinstall the whole site?

    Thread Starter Jason Judge

    (@judgej)

    If all you have changed is functions.php, then just restore that file back to the original copy. If you didn’t take a backup before fiddling with it, then extract it from the zip file of the WordPress version you installed originally.

    I didn’t make a back up and I have no idea where to find that zip file πŸ™ I installed WP with Fantastico.

    Plugin Author Remco Tolsma

    (@remcotolsma)

    @aldin30 did you solve the problem? If not could you send us our functions.php theme file?

    hi Remco,

    I payed someone on fiverr and they managed to get rid of the problem, so I can log in to my page but I don’t want to mess with the code anymore, so I’m just gonna skip the map

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Displaying a map at a shortcode’ is closed to new replies.