0

我正在尝试使用元框复选框在悬停时隐藏/显示。问题是如果任何帖子选中了复选框,它会显示 div。我需要它根据复选框是否被选中来切换 div “on”和“off”。任何帮助将不胜感激。这是我的functions.php中的代码:`// Checkbox Meta add_action("admin_init", "checkbox_init");

function checkbox_init(){
add_meta_box("checkbox", "Check to Show Bubbles", "checkbox", "homefeature", "normal",    "high");
}

function checkbox(){
global $post;
$custom = get_post_custom($post->ID);
$field_id = $custom["field_id"][0];

echo '<label>Show Bubbles?</label>';
$field_id_value = get_post_meta($post->ID, 'field_id', true);
if($field_id_value == "yes") {
$field_id_checked = 'checked="checked"';
}
echo ' <input type="checkbox" name="field_id" value="yes" '.$field_id_checked.' />';
}

// Save Meta Details
add_action('save_post', 'save_details');

function save_details(){
 global $post;

  if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
   return $post->ID;
}

update_post_meta($post->ID, "field_id", $_POST["field_id"]);
}

function custom_content($id) {
$field_id = get_post_meta($id, 'field_id', true);

if($field_id == yes) {
     echo '<script type="text/javascript">';
         echo '$("this").mouseover(function() {';
     echo "$('#mainFeatureFlashBG').css({'display' : 'block'})";
     echo '}</script>'; 
}
else{
   echo '<script type="text/javascript">';
       echo '$("this").mouseover(function() {';
   echo "$('#mainFeatureFlashBG').css({'display' : 'none'})";
   echo '}</script>';
}
}`

这是我的php:

        <ul>  
            <!-- Begin Miller Beer Logo Query-->                      
            <?php
            $args=array(
              'beerlogo'=>'miller',
              'post_type' => 'homefeature',
              'post_status' => 'publish',                
              'posts_per_page' => -1
            );
            $my_query = null; 
            $my_query = new WP_Query($args); 
            if( $my_query->have_posts() ) {

              while ($my_query->have_posts()) : $my_query->the_post(); ?>
                 <li class="image-rollover"><a href="<?php echo     esc_url(get_post_meta($post->ID, 'homefeature_custom_link', true));
            ?>"><?php the_post_thumbnail('full'); ?>               
            <?php
        //Is the Checkbox for Bubbles Checked?
        custom_content(get_the_ID());               
    ?>             

             </a>
            </li> 

                <?php
              endwhile;
            } 
            wp_reset_query(); 
            ?>
        </ul>
4

1 回答 1

0

您应该检查:

<?php

if(get_post_meta($post->ID,'field_id',true) != '') {
 // do something, output div
} ?>

请参阅此处的功能参考:

http://codex.wordpress.org/Function_Reference/get_post_meta

于 2012-09-05T16:40:08.100 回答