Skip to content

Instantly share code, notes, and snippets.

@jimmy89Li
Created October 4, 2015 23:56
Show Gist options
  • Save jimmy89Li/7531950363f11251164d to your computer and use it in GitHub Desktop.
Save jimmy89Li/7531950363f11251164d to your computer and use it in GitHub Desktop.
Custom Personal Information Widget for Footer
<?php
/*
Plugin Name: Personal Information Widget for Footer
Plugin URI: https://gist.github.com/jimmy89Li
Description: Custom widget for personal information
Author: jimmyLi
Version: 1.0.0
Author URI: https://gist.github.com/jimmy89Li
*/
class PersonalInformationWidget extends WP_Widget
{
function PersonalInformationWidget()
{
$widget_ops = array(
'classname' => 'site-footer-widget',
'description' => 'Displays Personal Information' );
$this->WP_Widget('PersonalInformationWidget', 'Personal Information Widget', $widget_ops);
}
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
?>
<?php echo $before_widget; ?>
<div class="col-1">
<?php echo ($instance['address']) ? '<div class="address">' . $instance['address'] . '</div>': ''; ?>
</div>
<div class="col-2">
<?php echo ($instance['phone']) ? '<div class="phone">Telephon: ' . $instance['phone'] . '</div>': ''; ?>
<?php echo ($instance['email']) ? '<div class="email">Email: <a href="mailto:' . $instance['email']. '">' . $instance['email'] . '</a></div>': ''; ?>
<?php echo ($instance['facebook']) ? '<div class="facebook">Facebook: <a href="http://facebook.com/' . $instance['facebook']. '">' . $instance['facebook'] . '</a></div>': ''; ?>
<?php echo ($instance['twitter']) ? '<div class="twitter">Twitter: <a href="http://twitter.com/' . $instance['twitter']. '">' . $instance['twitter'] . '</a></div>': ''; ?>
</div>
<?php echo $after_widget;?>
<?php
}
function form($instance)
{
?>
<label for="<?php echo $this->get_field_id('address'); ?>">
Address:
<textarea class="widefat" type="text" rows="4"
id="<?php echo $this->get_field_id('address'); ?>"
name="<?php echo $this->get_field_name('address'); ?>"><?php echo esc_attr($instance['address']); ?></textarea>
</label>
<label for="<?php echo $this->get_field_id('email'); ?>">
Email:
<input class="widefat" type="text"
id="<?php echo $this->get_field_id('email'); ?>"
name="<?php echo $this->get_field_name('email'); ?>"
value="<?php echo esc_attr($instance['email']); ?>" />
</label>
<label for="<?php echo $this->get_field_id('phone'); ?>">
Phone:
<input class="widefat" type="text"
id="<?php echo $this->get_field_id('phone'); ?>"
name="<?php echo $this->get_field_name('phone'); ?>"
value="<?php echo esc_attr($instance['phone']); ?>" />
</label>
<label for="<?php echo $this->get_field_id('facebook'); ?>">
Facebook:
<input class="widefat" type="text"
id="<?php echo $this->get_field_id('facebook'); ?>"
name="<?php echo $this->get_field_name('facebook'); ?>"
value="<?php echo esc_attr($instance['facebook']); ?>" />
</label>
<label for="<?php echo $this->get_field_id('twitter'); ?>">
Twitter:
<input class="widefat" type="text"
id="<?php echo $this->get_field_id('twitter'); ?>"
name="<?php echo $this->get_field_name('twitter'); ?>"
value="<?php echo esc_attr($instance['twitter']); ?>" />
</label>
<?php
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("PersonalInformationWidget");') );?>
/* Footer */
footer .col-1, footer .col-2 {
width:45%;
float:left;
padding:30px 0;
text-align:left;
}
footer .address, .contact-info .address {
background:transparent url(images/icon-address.png) no-repeat 0 6px;
padding:0 0 0 20px;
}
footer .email, .contact-info .email {
background:transparent url(images/icon-email.png) no-repeat 0 6px;
padding:0 0 0 20px;
}
footer .mobile, .contact-info .mobile {
background:transparent url(images/icon-mobile.png) no-repeat 0 6px;
padding:0 0 0 20px;
}
footer .phone, .contact-info .phone {
background:transparent url(images/icon-phone.png) no-repeat 0 6px;
padding:0 0 0 20px;
}
footer .twitter, .contact-info .twitter {
background:transparent url(images/icon-twitter.png) no-repeat 0 6px;
padding:0 0 0 20px;
}
footer .facebook, .contact-info .facebook {
background:transparent url(images/icon-facebook.png) no-repeat 0 6px;
padding:0 0 0 20px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment