first commit
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) {
|
||||
die( 'Direct access forbidden.' );
|
||||
}
|
||||
|
||||
if ( class_exists( 'Solarify_Widget_Popular' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
class Solarify_Widget_Popular extends WP_Widget {
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function __construct() {
|
||||
$widget_ops = array(
|
||||
'classname' => 'widget_popular_entries',
|
||||
'description' => esc_html__( 'Most commented Posts', 'solarify' ),
|
||||
);
|
||||
parent::__construct( false, esc_html__( 'Theme - Popular Posts', 'solarify' ), $widget_ops );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
* @param array $instance
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
extract( $args );
|
||||
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
|
||||
$number = ( (int) ( $instance['number'] ) > 0 ) ? esc_attr( $instance['number'] ) : 5;
|
||||
|
||||
$popular_posts = $this->fw_get_posts_with_info( array(
|
||||
'sort' => 'comment_count',
|
||||
'items' => $number,
|
||||
) );
|
||||
|
||||
$filepath = SOLARIFY_THEME_PATH . '/inc/widgets/popular/views/widget.php';
|
||||
|
||||
if ( file_exists( $filepath ) ) {
|
||||
include( $filepath );
|
||||
} else {
|
||||
esc_html_e( 'View not found', 'solarify' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fw_get_posts_with_info( $args = array() ) {
|
||||
$defaults = array(
|
||||
'sort' => 'recent',
|
||||
'items' => 5,
|
||||
'image_post' => true,
|
||||
'date_post' => true,
|
||||
'date_format' => 'F jS, Y',
|
||||
'post_type' => 'post',
|
||||
|
||||
);
|
||||
|
||||
extract( wp_parse_args( $args, $defaults ) );
|
||||
|
||||
$query = new WP_Query( array(
|
||||
'post_type' => $post_type,
|
||||
'orderby' => $sort,
|
||||
'order' => 'DESC',
|
||||
'ignore_sticky_posts' => true,
|
||||
'posts_per_page' => $items
|
||||
) );
|
||||
|
||||
//wp reset query removed
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $new_instance
|
||||
* @param array $old_instance
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function update( $new_instance, $old_instance ) {
|
||||
return $new_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $instance
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function form( $instance ) {
|
||||
$instance = wp_parse_args( (array) $instance, array( 'number' => '', 'title' => '' ) );
|
||||
$title = sanitize_text_field( $instance['title'] );
|
||||
$number = esc_attr( $instance['number'] );
|
||||
?>
|
||||
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'solarify' ); ?></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_html_e( 'Number of Blog posts', 'solarify' ); ?>
|
||||
:</label>
|
||||
<input type="text" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" value="<?php echo esc_attr( $number ); ?>"
|
||||
class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"/>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) {
|
||||
die( 'Direct access forbidden.' );
|
||||
}
|
||||
/**
|
||||
* @var string $before_widget
|
||||
* @var string $after_widget
|
||||
* @var array $popular_posts
|
||||
*/
|
||||
$unique_id = uniqid();
|
||||
|
||||
echo wp_kses_post( $before_widget );
|
||||
|
||||
if ( $title ) {
|
||||
echo wp_kses_post( $before_title . $title . $after_title );
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<ul id="popular_posts_<?php echo esc_attr( $unique_id ); ?>" class="media-list darklinks">
|
||||
<?php while ( $popular_posts->have_posts() ) : $popular_posts->the_post(); ?>
|
||||
<li <?php post_class( 'media' ); ?>>
|
||||
<?php if ( has_post_thumbnail() ) : ?>
|
||||
<a href="<?php the_permalink(); ?>" class="media-left">
|
||||
<?php echo get_the_post_thumbnail( get_the_ID(), 'thumbnail' ); ?>
|
||||
</a>
|
||||
<?php endif; //has_post_thumbnail ?>
|
||||
<div class="media-body">
|
||||
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
|
||||
<div class="item-meta">
|
||||
<?php
|
||||
// Set up and print post meta information.
|
||||
if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) : ?>
|
||||
<!-- comments number and link
|
||||
<span class="comments-link">
|
||||
<i class="rt-icon2-bubble highlight"></i>
|
||||
<?php comments_popup_link( esc_html__( 'No comments', 'solarify' ), esc_html__( '1 comment', 'solarify' ), esc_html__( '% comments', 'solarify' ) ); ?>
|
||||
</span>
|
||||
-->
|
||||
<?php
|
||||
endif; //post_password_required
|
||||
?>
|
||||
<span>
|
||||
<i class="rt-icon2-heart-outline highlight"></i>
|
||||
<?php
|
||||
solarify_post_like_count( get_the_ID() );
|
||||
?>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php endwhile; ?>
|
||||
<?php wp_reset_postdata(); // reset the query ?>
|
||||
</ul>
|
||||
<?php echo wp_kses_post( $after_widget ); ?>
|
||||
Reference in New Issue
Block a user