Home › Forums › MapPress Support › Custom Icon Per Term
Tagged: custom icons
- This topic has 5 replies, 3 voices, and was last updated 8 years, 11 months ago by
marijke.
-
AuthorPosts
-
November 15, 2014 at 10:09 am #15379
Rainmaster
ParticipantHi Chris,
Wordpress 4 MU, Catalyst Dynamik theme, have found only this one issue.
I have been using your Mappress Pro for quite a while now and I really appreciate this forum and your great support.
I have searched but cannot find an answer for my issue.
I am trying to use a custom icon for a particular taxonomy for a custom post.
I am using this code in my custom functions file which works find except…+++
function myiconid($iconid, $poi) {
global $post;
$postid = ($poi->postid) ? $poi->postid : $post->ID;if (has_term(‘vacation-rental’, ‘business-type’, $postid))
return ‘blue-dot’;
if (has_term(‘online-business’, ‘business-type’, $postid))
return ‘workoffice’;
return $iconid;
}
add_filter(‘mappress_poi_iconid’, ‘myiconid’, 10, 2);+++
If I use the default icons such as blue-dot, blue-pushpin, etc., this works fine but if I use uploaded icons like my work-office.png then I just get the default red-dot.png icon.
I found 2 icon folders, one within the mappress plugin which shows the default icons on the mappress admin page and the other within the WordPress uploads folder which I think is custom icons.
I guess there is something I am missing as I am not a programmer. I would try looking into the mappress-icons.php but not sure what to look for.
Thank you so much for your kind help.
November 15, 2014 at 10:10 am #15380Chris
KeymasterHi,
For custom icons you must return the file name WITH the extension. For example if the icon is ‘workoffice.png’ then your code should be:
if (has_term(‘online-business’, ‘business-type’, $postid)) return ‘workoffice.png’;
I think that may be why you’re getting the default icon instead of workoffice.png.
November 15, 2014 at 11:09 am #15381Rainmaster
ParticipantHi Chris,
Wow, thanks for the really fast reply.
I still get the default, that is whatever is set to default in the Mappress admin page. Everything works great except uploaded icons. Works ok for archives and single pages too, as long as a default icon is used in the code above.
November 15, 2014 at 11:16 am #15382Chris
KeymasterHi,
Have you uploaded ‘workoffice.png’ to the directory ‘/wp-content/uploads/mappress/icons’? If not, you’ll need to FTP it over to that directory.
Other than that, I’m not sure. Could you post your current code again?
You’re getting the default icon because the plugin can’t find the icon you set, or because nothing was set.
Try *always* returning ‘workoffice.png’ – then you’ll know whether the issue is with the code to check the taxonomy or with the icon itself. For example:
function myiconid($iconid, $poi) { return ‘workoffice.png’; }
November 15, 2014 at 1:53 pm #15383Rainmaster
ParticipantHey Chris,
I have it working now. Your code would have worked but when I copied it over the apostrophes were the old left-right type so I typed over them and works great now.
Thank you!
+++++++++
* For anyone interested here is the code for custom icons I am using…
function myiconid($iconid, $poi) {
global $post;
$postid = ($poi->postid) ? $poi->postid : $post->ID;if (has_term(‘custom-taxonomy’, ‘custom-post-type’, $postid))
return ‘custom-map-icon.png’;return $iconid;
}
add_filter(‘mappress_poi_iconid’, ‘myiconid’, 10, 2);* Icons loaded up to the “icons” folder somewhere within the “uploads” folder.
December 30, 2014 at 3:23 pm #15498marijke
ParticipantHi Chris and others,
I had the same problem and solved it with help from these replies, but I changed the code a bit. First I set $iconid to zero, to be sure that all icons are reset to the standard. Than I set my terms from my custom taxonomy. Terms that are not set will get the default icon.
function myiconid($iconid, $poi) { global $post; $postid = ($poi->postid) ? $poi->postid : $post->ID; $iconid=0; if (has_term('term1','mytax', $postid)) $iconid = 'term1.png'; if (has_term('term2','mytax', $postid)) $iconid = 'term2.png'; return $iconid; } add_filter('mappress_poi_iconid', 'myiconid', 10, 2);
-
AuthorPosts
- You must be logged in to reply to this topic.