Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/04/2013, 13:22
laura_moreno14
Invitado
 
Mensajes: n/a
Puntos:
recuperar opción en widget

Estoy creando un widget para mostrar el fanbox de facebook y me ha surgido un problema.

En el código para mostrar el fanbox incluye el ID de la pagina de facebook. Necesito crear una opción para que el usuario introduzca su ID.

Esto es lo que tengo hasta ahora. Pongo todo el código, tal vez no sea necesario, pero igual a alguien le es útil.


Código PHP:
Ver original
  1. class Facebook_FanBox extends WP_Widget {
  2.    
  3.     function Facebook_FanBox() {
  4.         /* Widget settings. */
  5.         $widget_ops = array( 'classname' => 'Facebook', 'description' => 'Show Facebook FanBox in a widget.' );
  6.  
  7.         /* Widget control settings. */
  8.         $control_ops = array( 'width' => 200, 'height' => 350, 'id_base' => 'facebook-fanbox' );
  9.  
  10.         /* Create the widget. */
  11.         $this->WP_Widget( 'facebook-fanbox', 'Facebook FanBox', $widget_ops, $control_ops );
  12.     }
  13.    
  14.     function widget( $args, $instance ) {
  15.         extract( $args );
  16.  
  17.         /* User-selected settings. */
  18.         $title = apply_filters('widget_title', $instance['title'] );
  19.         $id = $instance['page-id'];
  20.        
  21.         /* Before widget (defined by themes). */
  22.         echo $before_widget;
  23.  
  24.         /* Title of widget (before and after defined by themes). */
  25.         if ( $title )
  26.             echo $before_title . $title . $after_title;
  27.            
  28.             echo '<div class="fb-like-box" data-href="https://www.facebook.com/pages/mas-que-cienciacom/';
  29.             echo "$id";
  30.             echo '?ref=hl" data-width="300" data-show-faces="true" data-stream="true" data-border-color="fff" data-header="true"></div>';
  31.  
  32.         /* After widget (defined by themes). */
  33.         echo $after_widget;
  34.     }
  35.    
  36.     function update( $new_instance, $old_instance ) {
  37.         $instance = $old_instance;
  38.  
  39.         /* Strip tags (if needed) and update the widget settings. */
  40.         $instance['title'] = strip_tags( $new_instance['title'] );
  41.         $instance['page-id'] = $new_instance['page-id'] ;
  42.         return $instance;
  43.     }
  44.    
  45.     function form( $instance ) {
  46.  
  47.         /* Set up some default widget settings. */
  48.         $defaults = array( 'title' => 'Example', 'page-id' => '3');
  49.         $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  50.        
  51.         <p>
  52.             <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
  53.             <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
  54.         </p>
  55.        
  56.         <p>
  57.             <label for="<?php echo $this->get_field_id( 'page-id' ); ?>">Page ID:</label>
  58.             <input id="<?php echo $this->get_field_id( 'page-id' ); ?>" name="<?php echo $this->get_field_name( 'page-id' ); ?>" value="<?php echo $instance['page-id']; ?>" style="width:100%;" />
  59.         </p>
  60.        
  61.      
  62.         <?php
  63.        
  64.     }
  65. }


Como veis en la funcion que muetra el widget, intento guardarlo en $id = $instance['page-id'], que es lo que he utilizado con otras funciones con exito, pero no da resultado. Como es que si puedo recuperar el titulo y otras y esta variable no?