Making WordPress.org

Ticket #307: widgets2.php-meta-307.diff

File widgets2.php-meta-307.diff, 2.5 KB (added by bansod_deven, 10 years ago)

Tried to incorporate what georgestephanis suggested.

  • widgets.php

     
    2929
    3030                extract( $args );
    3131                $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
    32 
     32                $to_website = $instance['to_website'];
    3333                echo $before_widget;
    3434                if ( $title )
    3535                        echo $before_title . $title . $after_title;
     
    6666                                <h4 class="sponsor-level-title"><?php echo esc_html( $term->name ); ?></h4>
    6767
    6868                                <?php while ( $sponsors->have_posts() ) : $sponsors->the_post(); ?>
     69                                       
     70                                        <?php 
     71                                                /*
     72                                                 * Checks if $to_website is Checked in Widget Backend form
     73                                                 * If it is checked, checks if Sponsor's Website field is updated.
     74                                                 * If the website is updated, Links the Sponsor's Image to its website
     75                                                 * Else links it to its permalink
     76                                                 *
     77                                                 * If the $to_website is not checked in Widget Backend Form,
     78                                                 * it links the image to the Sponsor Permalink
     79                                                 *
     80                                                 */
    6981
    70                                         <a class="sponsor-logo" href="<?php the_permalink(); ?>">
     82                                                $website = get_permalink( $post_id );
     83
     84                                                if ( $to_website ) {
     85
     86                                                        $post_id = get_the_id();
     87                                               
     88                                                        $website = get_post_meta ( $post_id , '_wcpt_sponsor_website', TRUE );
     89
     90                                                        if ( ! $website )  {
     91
     92                                                                $website = get_permalink( $post_id );
     93
     94                                                        }
     95
     96                                                }
     97
     98                                        ?>
     99
     100                                        <a class="sponsor-logo" href="<?php echo esc_url( $website ) ?>">
    71101                                                <?php ( has_post_thumbnail() ) ? the_post_thumbnail() : the_title(); ?>
    72102                                        </a>
    73103
     
    86116                $title = $instance['title'];
    87117                ?>
    88118                <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', $this->textdomain ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /></label></p>
     119                <p>
     120                        <input class="checkbox" type="checkbox" <?php checked($instance['to_website'], 'on'); ?> id="<?php echo $this->get_field_id('to_website'); ?>" name="<?php echo $this->get_field_name('to_website'); ?>" />
     121                <label for="<?php echo $this->get_field_id('to_website'); ?>"><?php _e( "Link Image to Sponsors's Website", $this->textdomain ); ?></label>
     122        </p>
    89123                <?php
    90124        }
    91125
     
    93127                $instance = $old_instance;
    94128                $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '' ) );
    95129                $instance['title'] = strip_tags( $new_instance['title'] );
     130                $instance['to_website'] = $new_instance['to_website'];
    96131                return $instance;
    97132        }
    98133}