当我使用左侧边栏进行布局时,我的单页无法正常工作。这意味着,单页查询帖子来自左侧边栏的热门小部件的最后一篇文章。
我的课程:
class banyansopno_show_popular extends WP_Widget {
function banyansopno_show_popular() {
$widget_ops = array('classname' => 'banyansopno_show_popular', 'description' => esc_html__('Show your popular posts.', 'banyansopno'));
parent::__construct('banyansopno_show_popular', esc_html__('- @ Banyan Popular Posts @ -', 'banyansopno'), $widget_ops);
}
function widget($args, $instance){
extract($args);
$title = $instance['title'];
$postscount = $instance['posts'];
//GET the posts
$popularpost = new WP_Query( array( 'posts_per_page' => $postscount,'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC','post__not_in' => get_option( 'sticky_posts' ) ) );
echo '<h3 class="widget-title">'.$title.'</h3>' ;
//SHOW the posts
while ( $popularpost->have_posts() ) : $popularpost->the_post();
?>
<div class="widget widget_latest_posts_entries">
<ul>
<li>
<div class="featured-image">
<a href="<?php echo esc_url(get_permalink()); ?>"><?php echo get_the_post_thumbnail(); ?></a>
</div>
<div class="post-content">
<p class="post-title"><a href="<?php echo esc_url(get_permalink()); ?>"><?php the_title(); ?></a></p>
<span class="category">
<?php if( esc_attr(get_theme_mod( 'show_categories', 1 ) ) ) {
banyansopno_categories_list();
} ?>
</span>
<span class="post-date"><?php the_date('F j, Y'); ?> at <?php the_time('g:i a'); ?></span>
</div>
</li>
</ul>
</div>
<?php
endwhile;
}
function update($newInstance, $oldInstance){
$instance = $oldInstance;
$instance['title'] = strip_tags($newInstance['title']);
$instance['posts'] = $newInstance['posts'];
return $instance;
}
function form($instance){
$title = isset($instance['title'])? $instance['title'] : 'Popular Post\'s';
echo '<p style="text-align:right;"><label for="'.$this->get_field_id('title').'">' . esc_html__('Title:', 'banyansopno') . ' <input style="width: 200px;" id="'.$this->get_field_id('title').'" name="'.$this->get_field_name('title').'" type="text" value="'.esc_attr($title).'" /></label></p>';
$posts = isset($instance['posts'])? $instance['posts'] : '3';
echo '<p style="text-align:right;"><label for="'.$this->get_field_id('posts').'">' . esc_html__('Number of Posts:', 'banyansopno') . ' <input style="width: 50px;" id="'.$this->get_field_id('posts').'" name="'.$this->get_field_name('posts').'" type="text" value="'.esc_attr($posts).'" /></label></p>';
echo '<input type="hidden" id="custom_recent" name="custom_recent" value="1" />';
}
}
add_action('widgets_init', create_function('', 'return register_widget("banyansopno_show_popular");'));
你能帮我解决这个问题吗?