Custom Icon Per Term

Home Forums MapPress Support Custom Icon Per Term

Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #15379
    Rainmaster
    Participant

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

      #15380
      Chris
      Keymaster

        Hi,

        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.

        #15381
        Rainmaster
        Participant

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

          #15382
          Chris
          Keymaster

            Hi,

            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’;
            }
            #15383
            Rainmaster
            Participant

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

              #15498
              marijke
              Participant

                Hi 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); 
              Viewing 6 posts - 1 through 6 (of 6 total)
              • You must be logged in to reply to this topic.