- This topic has 7 replies, 3 voices, and was last updated 6 years, 6 months ago by
Steve.
-
AuthorPosts
-
-
August 3, 2015 at 7:15 am #4106
subaleeMemberHey,
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 🙂
-
August 3, 2015 at 8:42 am #4107
jcristMemberYou 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/
-
August 4, 2015 at 7:03 am #4128
subaleeMemberSeems 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 🙂
-
August 4, 2015 at 7:18 am #4130
subaleeMemberCan’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>
-
-
August 3, 2015 at 10:08 am #4111
-
August 4, 2015 at 9:44 am #4133
SteveKeymasterBoth @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.
-
August 4, 2015 at 8:45 pm #4142
subaleeMemberYep, 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 🙂
-
August 4, 2015 at 8:50 pm #4143
SteveKeymasterGlad it worked! Closing ticket.
-
-
AuthorPosts
- The topic ‘metabox select for font awesome’ is closed to new replies.