WordPress.org

Ready to get started?Download WordPress

Forums

Pronamic Google Maps
[resolved] Displaying a map at a shortcode (18 posts)

  1. Jason Judge
    Member
    Posted 2 years ago #

    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

  2. psyborg
    Member
    Posted 2 years ago #

    This is great! Thank you for sharing!! Would it be possible to add a parameter for a static map?

  3. Jason Judge
    Member
    Posted 2 years ago #

    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 ;-)

  4. Remco Tolsma
    Member
    Plugin Author

    Posted 2 years ago #

    @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.

  5. flick
    Member
    Posted 2 years ago #

    @JudgeJ: Thanks for sharing your solution with us.

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

  6. Remco Tolsma
    Member
    Plugin Author

    Posted 2 years ago #

    @flick We will launch version 2.0 this week.

  7. flick
    Member
    Posted 2 years ago #

    Thanks Remco :)

  8. aldin30
    Member
    Posted 2 years ago #

    @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

  9. Jason Judge
    Member
    Posted 2 years ago #

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

  10. aldin30
    Member
    Posted 2 years ago #

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

  11. Jason Judge
    Member
    Posted 2 years ago #

    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.

  12. aldin30
    Member
    Posted 2 years ago #

    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?

  13. Jason Judge
    Member
    Posted 2 years ago #

    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.

  14. aldin30
    Member
    Posted 2 years ago #

    I didn't make a back up and I have no idea where to find that zip file :( I installed WP with Fantastico.

  15. Remco Tolsma
    Member
    Plugin Author

    Posted 2 years ago #

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

  16. aldin30
    Member
    Posted 2 years ago #

    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

  17. Jason Judge
    Member
    Posted 2 years ago #

    Hehe - I would have done it for four ;-)

    Seriously through, glad you got it sorted. Software is like that - you type one single character that it does not like, and it won't forgive you. You always need to make sure you have a way to back out again, and that means backing up files before you change them.

    Oh, and if you have given out access passwords to people you don't know, make sure you change the passwords once they have done the job.

  18. aldin30
    Member
    Posted 2 years ago #

    yeah, thanx, I'll try to make back up before I do something else stupid :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic