samedi 28 février 2015

get_option function


I'm currently trying to make my own theme, but i'm not quite sure how the get_option() function works, because how come this..



echo get_option('show_header', 'sultenhest_theme_display_options');
echo get_option('sultenhest_theme_display_options')['show_header'];


..both returns 1 (but Dreamweaver doesnt like the second option). While



echo get_option('twitter', 'sultenhest_theme_social_options');


..simply returns 'sultenhest_theme_social_options', which is incorrect.


An option would be to define the array as such



$social_options = get_option( 'sultenhest_theme_social_options' );


and call it like this



echo $social_options['twitter'];


It returns the correct string, but it only works in the header.php (if the array is defined there) file and not in, e.g. footer.php.




UPDATE: Following partly ialocin and Brad Dalton i came up with this solution, which works like a charm:



function sultenhest($option, $arg){
$the_array = array();
foreach( get_option('sultenhest_theme_'.$option) as $key => $item ){
$the_array[$key] = $item;
}
return $the_array[$arg];
}


and echoing it out like this:



echo sultenhest('social_options', 'twitter') ? '<a href="' . sultenhest('social_options', 'twitter') . '">Twitter</a>' : '';




Aucun commentaire:

Enregistrer un commentaire