WordPress.org

Ready to get started?Download WordPress

Forums

Basic Google Maps Placemarks
Custom category markers not working (16 posts)

  1. 3stripe
    Member
    Posted 1 year ago #

    Have added the following to my functions.php file as a proof of concept, as I have 1 placemarker which assisgned only to my 'shop' category:

    function setBGMPDefaultIconByCategory( $iconURL, $placemarkID )
    {
        $placemarkCategories = wp_get_object_terms( $placemarkID, 'bgmp-category' );
    
        foreach( $placemarkCategories as $pc )
            if( $pc->slug == 'shop' ) {
                $iconURL = 'http://www.gravatar.com/avatar/1cf0770522223715996d00a7fe911003?s=48&d=monsterid&r=g';
    		} else {
    			$iconURL = get_bloginfo( 'stylesheet_directory' ) . '/img/map_marker_generic.png';
    		}
        return $iconURL;
    }
    add_filter( 'bgmp_default-icon', 'setBGMPDefaultIcon', 10, 2);

    No markers at all are showing on my map, and I'm getting error messges for each placemark:

    bgmp_createMarker(): Postname icon wasn't passed in.

    I've tried disabling all other plugins and switching to default theme.

    Running locally on MAMP but can upload if it helps.

    Guess I must be missing something obvious?

    http://wordpress.org/extend/plugins/basic-google-maps-placemarks/

  2. 3stripe
    Member
    Posted 1 year ago #

    PS. Some of my places are assigned to multiple categories.

  3. Ian Dunn
    Member
    Plugin Author

    Posted 1 year ago #

    This might not be the only problem, but I'm pretty sure you'll need curly braces around the foreach... loop.

  4. 3stripe
    Member
    Posted 1 year ago #

    Thanks for the heads up! (I copied that text from your readme btw)

    It must be something else unless this is still not right:

    function setBGMPDefaultIconByCategory( $iconURL, $placemarkID )
    {
        $placemarkCategories = wp_get_object_terms( $placemarkID, 'bgmp-category' );
    
        foreach( $placemarkCategories as $pc )
            if( $pc->slug == 'shop' ) {
                $iconURL = 'http://www.gravatar.com/avatar/1cf0770522223715996d00a7fe911003?s=48&d=monsterid&r=g';
    		} else {
    			$iconURL = get_bloginfo( 'stylesheet_directory' ) . '/img/map_marker_generic.png';
    		}
        return $iconURL;
    }
    add_filter( 'bgmp_default-icon', 'setBGMPDefaultIcon', 10, 2);
  5. 3stripe
    Member
    Posted 1 year ago #

    Have resorted to hacking the core.php file until I figure this out :)

  6. Ian Dunn
    Member
    Plugin Author

    Posted 1 year ago #

    The bit in the readme works because there's only a single line inside the foreach. When you add multiple lines, then you need to wrap them in braces; otherwise you can get unexpected results.

    You would need to do something like

    foreach( $placemarkCategories as $pc )
    {
    	if( $pc->slug == 'shop' )
    	{
    		$iconURL = 'http://www.gravatar.com/avatar/1cf0770522223715996d00a7fe911003?s=48&d=monsterid&r=g';
    	}
    	else
    	{
    		$iconURL = get_bloginfo( 'stylesheet_directory' ) . '/img/map_marker_generic.png';
    	}
    }
  7. MediamusNL
    Member
    Posted 1 year ago #

    I almost threw my laptop out of the window trying to fix this. Was looking through the code for hours.

    Bottom line, it was the bottom line:

    'setBGMPDefaultIcon' should be 'setBGMPDefaultIconByCategory'

    function setBGMPDefaultIconByCategory( $iconURL, $placemarkID )
    {
        $placemarkCategories = wp_get_object_terms( $placemarkID, 'bgmp-category' );
    
        foreach( $placemarkCategories as $pc )
            if( $pc->slug == 'shop' ) {
                $iconURL = 'http://www.gravatar.com/avatar/1cf0770522223715996d00a7fe911003?s=48&d=monsterid&r=g';
    		} else {
    			$iconURL = get_bloginfo( 'stylesheet_directory' ) . '/img/map_marker_generic.png';
    		}
        return $iconURL;
    }
    add_filter( 'bgmp_default-icon', 'setBGMPDefaultIconByCategory', 10, 2);

    -_-'

  8. jesse.t
    Member
    Posted 1 year ago #

    If you're doing multiple lines. It'd be much more efficient to use switch instead of if statements. food for thought.

    switch($pc->slug) {
      case 'shop' : $iconURL; break;
      case 'store': $iconURL; break;
      default: $iconURL; break; 
    
    }
  9. msmithwisedu
    Member
    Posted 1 year ago #

    Jesse.t
    can you give an example of the whole function using switch? I am a PHP novice. Thanks

  10. jesse.t
    Member
    Posted 1 year ago #

    Sure.

    http://pastebin.com/QG9NvX1p

    replace slug in case 'slug': with the slug of your categories.. And change the iconURL to reflect your icons.

  11. H_Andrea
    Member
    Posted 1 year ago #

    Hello,

    Thank you for the great plugin! I tried to use a different picture for 3 categories, but unfortunately the places disappeared on the map.
    I used the belowing code and I added it with the "Add function" wordpress plugin.

    Plese be so kind and help me, what is the problem?

    Thank you very much,
    Andrea

    <?php
    function setBGMPDefaultIconByCategory( $iconURL, $placemarkID )
    {
        $placemarkCategories = wp_get_object_terms( $placemarkID, 'bgmp-category' );
    
        foreach( $placemarkCategories as $pc ) {
            switch($pc->slug) {
    		case 'headoffice' : $iconURL = get_bloginfo('http://web-reneszansz.hu/recept_blog/wp-content/themes/twentyeleven').'/images/headoffice-marker.png'; break;
    		case 'agents' : $iconURL = get_bloginfo('http://web-reneszansz.hu/recept_blog/wp-content/themes/twentyeleven').'/images/agents-marker.png'; break;
    		case 'portfolios' : $iconURL = get_bloginfo('http://web-reneszansz.hu/recept_blog/wp-content/themes/twentyeleven').'/images/portfolios-marker.png'; break;
    		default : $iconURL = get_bloginfo('http://web-reneszansz.hu/recept_blog/wp-content/themes/twentyeleven').'/images/portfolios-marker.png'; break;
    		}
    	}
        return $iconURL;
    }
    add_filter( 'bgmp_default-icon', 'setBGMPDefaultIconByCategory', 10, 2);
    ?>

    [Please post code between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

  12. Ian Dunn
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Andrea,

    get_bloginfo('http://web-reneszansz.hu/recept_blog/wp-content/themes/twentyeleven').

    is probably part of the problem. Take a look at the WordPress Codex entry for get_bloginfo(). You want to be calling get_bloginfo( 'wpurl' ) instead.

    Better yet, use get_stylesheet_directory_uri() to get the URL of your theme.

    If that doesn't fix it completely, I'd view the page source and look at what URLs are being generated for the marker, or use Firebug/Chrome Dev Tools to select the marker and look at the HTML to see.

  13. H_Andrea
    Member
    Posted 1 year ago #

    Hello Ian,
    Great, it works!!!
    Thank you very much for the prompt answer, I really appreciate it,
    BR
    Andi

  14. H_Andrea
    Member
    Posted 1 year ago #

    Hello Ian,
    One more question please, would it be possible to delete my full url of web-reneszansz.hu from the published code and use my question only as a example?
    Thank you very mutch,
    Andi

  15. H_Andrea
    Member
    Posted 1 year ago #

    and also this related message... :)

  16. Ian Dunn
    Member
    Plugin Author

    Posted 1 year ago #

    Plugin authors don't have the capability to edit other people's posts. You'll have to ask one of the forum moderators to do that, by adding the "modlook" tag to the thread.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.