L-am ajutat pe Andrei la un proiect cu un widget facut special in care sa adaugi direct un link si url la o poza si as vrea sa va dau codurile cine stie daca nu va ajuta si pe voi. In mod normal pui in text html widgetul de baza de la WordPress si construiesti ceva de genul <a href=”link”><img src=”lin poza” alt=”” /></a> dar acum nu mai este nevoie decat sa incarci poza via media si sa iai linkul sa il pui acolo in widgetul nou facut de mine…
Copiati codul si se introduce in functions.php al temei.
class simple_link_Widget_Text extends WP_Widget { function __construct() { $widget_ops = array('classname' => 'widget_simple_link', 'description' => __('Widget imagine cu link', 'owd')); $control_ops = array('width' => 400, 'height' => 350); parent::__construct('simple_link', __('Widget imagine cu link »','owd'), $widget_ops, $control_ops); } function widget( $args, $instance ) { extract($args); $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); $text3 = apply_filters( 'widget_text', empty( $instance['text3'] ) ? '' : $instance['text3'], $instance ); $text4 = apply_filters( 'widget_text', empty( $instance['text4'] ) ? '' : $instance['text4'], $instance ); echo $before_widget; if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?> <div class="iasi-widget" style="max-width:100%;"> <a href="<?php echo !empty( $instance['filter'] ) ? wpautop( $text4 ) : $text4; ?>" target="_blank"><img src="<?php echo !empty( $instance['filter'] ) ? wpautop( $text3 ) : $text3; ?>" alt=""></a> </div> <?php echo $after_widget; } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); if ( current_user_can('unfiltered_html') ) { $instance['text3'] = $new_instance['text3']; $instance['text4'] = $new_instance['text4']; } else { $instance['text3'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text3']) ) ); $instance['text4'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text4']) ) ); } $instance['filter'] = isset($new_instance['filter']); return $instance; } function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text3' => '', 'text4' => '' ) ); $title = strip_tags($instance['title']); $text3 = esc_textarea($instance['text3']); $text4 = esc_textarea($instance['text4']); ?> <p><label for="<?php echo $this->get_field_id('text3') ?>"><?php _e('Widget link', 'owd'); ?></label> <p><label for="<?php echo $this->get_field_id('text3') ?>"><?php _e('Adauga URL imagine', 'owd'); ?></label> <input class="widefat" style="border:1px solid #ccc;box-shadow:0 0 10px 0 #ccc;background:#EEEEEE;" id="<?php echo $this->get_field_id('text3'); ?>" name="<?php echo $this->get_field_name('text3'); ?>" type="text" value="<?php echo $text3; ?>" /></p> <p><label for="<?php echo $this->get_field_id('text4') ?>"><?php _e('Adauga link', 'owd'); ?></label> <input class="widefat" style="border:1px solid #ccc;box-shadow:0 0 10px 0 #ccc;background:#EEEEEE;" id="<?php echo $this->get_field_id('text4'); ?>" name="<?php echo $this->get_field_name('text4'); ?>" type="text" value="<?php echo $text4; ?>" /></p> <?php } } add_action( 'widgets_init', create_function( '', 'register_widget( "simple_link_Widget_Text" );' ) );
Acum ar trebui sa vedeti ceva de genul asta la widgets