Viewing 5 reply threads
  • Author
    Posts
    • #4106
      subalee
      Member

      Hey,

      I’m very new to wordpress (trying to make my first theme) and i’m using piklist.

      I created several custom post types The one i’m trying to create now has icon it, what I’d like to do is create a dropdown select to choose the icon for the posts inside that custom post type. The icons are from font awesome, they are not images it’s something like this:

      <i class="fa fa-paint-brush"></i>

      I could cho the second class name but it wouldn’t be very user friendly when viewed as an option.

      What I’d like to do is to make option 1: “Paint Brush” and then perhaps and if statement that would output “fa-paint-brush” if option1 = “Paint Brush”, though i’m not sure if this is very effective or even where should i put the if statements.

      Any help appreciated 🙂

    • #4107
      jcrist
      Member

      You can use this: https://github.com/tommusrhodus/FontAwesome-4.3.0-Class-Names/blob/master/array.php

      to create a select meta-box like this:

      piklist('field', array(
          'type' => 'select'
          ,'field' => 'font-awesome-icon'
          ,'label' => __('Icon', 'piklist-demo')
          ,'choices' => ebor_icons_list()
        ));

      Then show the icon like this:

      <?php $font_awesome_icon = get_post_meta(get_the_ID(), 'font-awesome-icon'); ?>
      <i class="fa <?php echo $font_awesome_icon; ?>"></i>

      And if you want to get real fancy: http://mjolnic.com/fontawesome-iconpicker/

      • #4128
        subalee
        Member

        Seems like a great solution, however I’m rather inexperienced with php and wordpress

        Where exactly should i store the array.php?

        EDIT: nevermind, figured it out, thanks again 🙂

      • #4130
        subalee
        Member

        Can’t edit second time but this is what it outputs:

        <i class="fa <br />
        <b>Notice</b>:  Array to string conversion in <b>/home/html/grg.sk/public_html/_sub/dusan/dummytest/wp-content/themes/theme/templates/blocks/block-aboutus.php</b> on line <b>18</b><br />
        Array"></i>
    • #4111
      Steve
      Keymaster

      @jcrist– Nice! Love the Font Awesome class names.

    • #4133
      Steve
      Keymaster

      @subalee

      Both @jcrist and I left something out. When using the standard WordPress function get_post_meta, it returns the value in an array by default. This is mentioned in the official Codex. If you don’t want an array returned, you need to set $single to true.

      So, you code should actually look like this:

      <?php $font_awesome_icon = get_post_meta(get_the_ID(), 'font-awesome-icon', true); ?>

      <i class="fa <?php echo $font_awesome_icon; ?>"></i>

      Let us know if that works for you.

    • #4142
      subalee
      Member

      Yep, thank you so much, I really appreciate your time,

      I actually figured out that something was missing by adding something behind the ‘font-awesome-icon’ (actualy it was code for setting image size on post thumbnail) and it suddenly worked.

      Thanks again 🙂

    • #4143
      Steve
      Keymaster

      Glad it worked! Closing ticket.

Viewing 5 reply threads
  • The topic ‘metabox select for font awesome’ is closed to new replies.