Log in

View Full Version : Need some help with a php select form to show correct result



gwmbox
08-01-2014, 08:57 AM
I am working on a theme for Wordpress and I want to add a function where a user can in the theme options select a font they want to use for their content etc

I have the basics working using the following in my options and functions files, the following are just the excerpts of the code for this particular issue;

in my options.php file


$options[] = array(
'name' => __('Content Font', 'flexiness'),
'desc' => __('Select the font you want to use for your main content areas.', 'flexiness'),
'id' => 'content_font',
'type' => 'select',
'std' => 'arial', // as default
'options' => array(
'arial' => 'Arial/Helvetica',
'arial_blk' => 'Arial Black',
'comic' => 'Comic Sans MS',
'georgia' => 'Georgia',
'impact' => 'Impact',
'lucida' => 'Lucida Sans Unicode',
'palatino' => 'Palatino Linotype',
'tahoma' => 'Tahoma',
'times' => 'Times New Roman',
'trebuchet' => 'Trebuchet MS',
'verdana' => 'Verdana, Geneva, sans-serif')
);


then in my functions php file which gets its content from the options chosen above


$flexiness_content_font = flexiness_option('content_font', 'arial'); // this is the default

Then, noting there is other style code above this including the opening style tag

I will be adding Google font options as an alternative hence the if and or's, if they choose the google fonts instead it will output the required google link code instead of the following


if ($flexiness_content_font == 'arial' || 'arial_blk' || 'comic' || 'georgia' || 'impact' || 'lucida' || 'palatino' || 'tahoma' || 'times' || 'trebuchet' || 'verdana'); {
echo '
h1, h2, h3, h4, h5, h6, #theme-link, #nav-main .nav-main a, #nav-top .nav-top a, .my-title {font-family:' . ($flexiness_content_font) . ';}
</style>' . "\n";}

The end result is that if 'arial_blk' is selected it outputs of course 'arial_blk'. How can I get it to instead output the full name like 'Arial Black', or for 'comic', output 'Comic Sans MS'

I'm sure there is a better and more efficient way to do the above, but for now I just need to work out how I get it to output the full name.

Hoping the above is enough to make sense ;)

gwmbox
08-07-2014, 11:26 AM
All sorted, I have used a combination of the full name font and used php to title and remove underscores etc to produce the right font name and now have an optional font selection for my theme :)

tuanx90
08-15-2014, 02:35 AM
i'm searching to solve this problem