Set Gmap Icon to different categories with php

61 views Asked by At

I am a rookie with PHP, so here's my question.

I want to add a custom marker ICON on GoogleMap to each category.

Here what I want to do: icon:

"if php listing-type=6 ?>/images/red-marker.png"<br/>
"if php listing-type=7 ?>/images/blue-marker.png"

The code I have:

options: {
    icon : "<?php echo get_template_directory_uri(); ?>/images/red-marker.png"
},

Here it´s the full code:

http://descubrime.com.ar/fullcode.txt

And here its the site:

http://descubrime.com.ar/

I am completly lost!

1

There are 1 answers

0
Rash On

I am not clear on what you are asking, but I am almost sure you want something like this. Please alert me if you were asking something else.

Since you are a beginner, I will try and explain myself.

<?php
$parentDirectory = get_template_directory_uri();
$listingType = getListingType();
$icon = ""

if($listingType == 6)
{
    $icon = $parentDirectory . "/images/red-marker.png"
}
else
{
    $icon = $parentDirectory . "/images/blue-marker.png"
}
?>




options: {
        icon : "<?php echo $icon; ?>"
    },

Your basic question is to inject the path of your icon dynamically in your javascript. So anywhere before the options line, you start to declare the above php code and declare your parentDirectory and the listing type. I have used a method getListingType() which can be anything to get the listing (6, 7 whatever). Then based on the type I prepare my $icon variable which contains the dynamic path to your actual file.