Commit 1ebd9c62 authored by Bruno Antunes Magrini's avatar Bruno Antunes Magrini

Move functions from template to widget php file

parent 057a6d9a
......@@ -12,15 +12,25 @@ if(!class_exists('\\AjaxPageviews')){
}
class MostReadPostsList extends PostsList {
function __construct() {
parent::__construct(false);
$fields = $this->fields;
parent::__construct('most-read-posts-list', 'Lista de posts Mais lidos', '', '', '', plugin_dir_path(__FILE__));
}
function get_template_variables($instance, $args) {
if (isset($instance['conteudo'])) {
parse_str($instance['conteudo'], $conteudo);
$date = json_decode($conteudo['date_query']);
}
$posts_query_args = siteorigin_widget_post_selector_process_query($instance['conteudo']);
$most_read = \AjaxPageviews::get_top_viewed(1000, ['post_type' => $conteudo['post_type'], 'from' => $date->after]);
$ids = array();
foreach ($most_read as $post => $value) {
array_push($ids, $value->post_id);
}
$posts_query_args['post__in'] = $ids;
$posts_query_args['orderby'] = 'post__in';
$most_read_query = new \WP_Query($posts_query_args);
return [
'query_args' => $posts_query_args,
'link' => (object) $instance['link']
'query' => $most_read_query,
'link' => (object) $instance['link']
];
}
}
......
......@@ -4,23 +4,7 @@ $show_images = $instance['show_images'];
$show_excerpt = $instance['show_excerpt'];
$hide_categories = $instance['hide_categories'];
$css_classes = $instance['css_class'];
$link = $instance['link'];
if (isset($instance['conteudo'])) {
parse_str($instance['conteudo'], $conteudo);
$date = json_decode($conteudo['date_query']);
}
$i = 0;
$most_read = AjaxPageviews::get_top_viewed(1000, ['post_type' => $conteudo['post_type'], 'from' => $date->after]);
$ids = array();
foreach ($most_read as $post => $value) {
array_push($ids, $value->post_id);
}
$query_args['post__in'] = $ids;
$query_args['orderby'] = 'post__in';
$query = new WP_Query($query_args);
?>
<div class="posts-list <?= $css_classes ?>">
<div class="row">
......@@ -70,9 +54,9 @@ $query = new WP_Query($query_args);
wp_reset_postdata();
?>
</div>
<?php if($link['url']): ?>
<?php if($link->url): ?>
<div class="read-more" >
<a class="read-more-link" href="<?= $link['url'] ?>" class="goto"><?= $link['label'] ?></a>
<a class="read-more-link" href="<?= $link->url ?>" class="goto"><?= $link->label ?></a>
</div>
<?php endif; ?>
</div>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment