| Server IP : 68.183.124.220 / Your IP : 216.73.216.141 Web Server : Apache/2.4.18 (Ubuntu) System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : gavin ( 1000) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/wp-content/plugins/aperture-real-estate-pro/includes/widgets/ |
Upload File : |
<?php
// register My_Widget
add_action( 'widgets_init', function(){
register_widget( 'Property_Widget' );
});
class Property_Widget extends WP_Widget {
// class constructor
public function __construct() {
$widget_ops = array(
'classname' => 'property_widget',
'description' => 'Aperture Real estate Property Widgets',
);
parent::__construct( 'property_widget', 'Aperture Property Widget', $widget_ops );
}
// output the widget content on the front-end
public function widget( $args, $instance ) {
echo $args['before_widget'];
if ( ! empty( $instance['title'] ) ) {
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
}
$number = ! empty( $instance['number'] ) ? $instance['number'] : '5';
$status = ! empty( $instance['status'] ) ? $instance['status'] : '';
$currency = get_field('currency','option');
global $post;
$vars = array(
'post_type' => 'property',
'posts_per_page' => $number,
'meta_key' => 'status',
'meta_value' => $status,
);
$property = new WP_Query( $vars);
if($property->have_posts()):
echo '<div class="clear">';
while($property->have_posts()): $property->the_post();
$price = get_field('price');
echo '<div class="property-in-widget clear">';?>
<?php
if ( has_post_thumbnail() ) {
$thumb = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
}
else {
$thumb = get_template_directory_uri() .'/img/header-default.jpg';
} ?>
<div class="col-3-12">
<a href="<?php the_permalink(); ?>" >
<div class="thumbnail" style="background-image:url('<?php echo $thumb; ?>'); background-size: cover;"></div>
</a>
</div>
<div class="col-9-12 clear dets">
<?php
the_title('<h5 class="p-title">','</h5>');
echo '<span>'. $currency, $price .'</span><br/>';
echo '<span class="location">';
the_terms( $post->ID, 'location' );
echo '</span>';
?>
</div>
<?php
echo '</div>';
endwhile;
echo '</div>';
endif;
echo $args['after_widget'];
}
// output the option form field in admin Widgets screen
public function form( $instance ) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'Latest Properties', 'aperture-real-estate-pro' );
$number = ! empty( $instance['number'] ) ? $instance['number'] : '5';
$status = ! empty( $instance['status'] ) ? $instance['status'] : '';
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
<?php esc_attr_e( 'Title:', 'aperture-real-estate-pro' ); ?>
</label>
<input
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
type="text"
value="<?php echo esc_attr( $title ); ?>">
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>">
<?php esc_attr_e( 'Number Of Properties:', 'aperture-real-estate-pro' ); ?>
</label>
<input
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>"
type="text"
value="<?php echo esc_attr( $number ); ?>">
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'status' ) ); ?>">
<?php esc_attr_e( 'Property Contract:', 'aperture-real-estate-pro' ); ?>
</label>
<select
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'status' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'status' ) ); ?>" >
<option <?php selected( $instance['status'], ''); ?> value="">All</option>
<option <?php selected( $instance['status'], 'rent'); ?> value="rent">Rental</option>
<option <?php selected( $instance['status'], 'sale'); ?> value="sale">Sale</option>
<option <?php selected( $instance['status'], 'sold'); ?> value="sold">Sold</option>
</select></p>
<?php
}
// save options
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
$instance['number'] = ( ! empty( $new_instance['number'] ) ) ? strip_tags( $new_instance['number'] ) : '';
$instance['status'] = ( ! empty( $new_instance['status'] ) ) ? strip_tags( $new_instance['status'] ) : '';
return $instance;
}
}