Ive given my wordpress user a custom field in the backend which is a radio selection with three values, 1,2,3.
I want to set up conditionals so that if they select 1 then image 1 appears, if they select 2 then image 2 appears and if they select 3 then image 3 appears.
I'm currently using the following displays all thvalues of the checked buttons - but I need to use do do something like if value = 1 then do this
<?php
/** Get a custom field with multiple values and return as an array */
$checkboxes_1 = get_custom_field('cft_checkboxes_1');
if( $checkboxes_1 ) {
?>
<div id="block-1" class="content-box">
<h2>Custom Field (multiple)</h2>
<div class="entry">
<?php print_r($checkboxes_1); ?>
</div>
</div>
<?php } ?>
the custome fields are generated using the custom field template button, and the implementation 开发者_C百科of getting the results is down to kevin leary
I've put this in my functions.php to retreive the cutom fields from the database...
// Get Custom Field Template Values
function get_custom_field($field) {
global $post;
$custom_field_data = get_post_meta($post->ID, $field, false);
if($custom_field_data) {
if( count($custom_field_data) > 1 ) {
return $custom_field_data;
} else {
return $custom_field_data[0];
}
} else {
return false;
}
}
thanks!
Give some values to the radio buttons:
<input name="option" type="radio" value="1">
<input name="option" type="radio" value="2">
<input name="option" type="radio" value="3">
Insert those values into the database, and then query the database to see what is the value of the field for a specific user.
Ok sorted it thanks for a great hack kevin leary for an amazing plugin: custom_field_templates
<?php
/** Get a custom field with multiple values and return as an array */
$checkboxes_1 = get_custom_field('mycustomfield');
if(($checkboxes_1 ) == 1) {
?>
// do something
<?php } else if(($checkboxes_1 ) == 2) {?>
// do something
<?php } else if(($checkboxes_1 ) == 3) { ?>
// do something
<?php } ?>
精彩评论