function widget($args, $instance) { extract($args); @($title = $instance['title'] ? $instance['title'] : '最热文章'); @($num = $instance['num'] ? $instance['num'] : 5); echo $before_widget; ?> <div class="panel panel-zan hidden-xs"> <div class="panel-heading"><?php echo $title; ?> </div> <div class="panel-body"> <ul class="list-group"> <?php // 设置全局变量,实现post整体赋值 global $post; $posts = zan_get_hotest_posts($num); foreach ($posts as $post) { setup_postdata($post); ?> <li class="zan-list clearfix"> <figure class="thumbnail zan-thumb"> <?php the_post_thumbnail(array(75, 75)); ?> </figure> <a href="<?php the_permalink(); ?> "> <h5><?php the_title(); ?> </h5> </a> <div class="sidebar-info"> <span><i class="fa fa-calendar"></i> <?php the_time('m月j日, Y'); ?> </span> <span><i class="fa fa-comment"></i> <a href="<?php the_permalink(); ?> #comments"><?php comments_number('0', '1', '%'); ?> </a></span> </div> </li> <?php } wp_reset_postdata(); ?> </ul> </div> </div> <?php echo $after_widget; }
function widget($args, $instance) { extract($args); @($title1 = $instance['title1'] ? $instance['title1'] : '最热文章'); @($title2 = $instance['title2'] ? $instance['title2'] : '最新文章'); @($title3 = $instance['title3'] ? $instance['title3'] : '随机文章'); @($num = $instance['num'] ? $instance['num'] : 8); echo $before_widget; ?> <div class="panel panel-zan widget-sets hidden-xs"> <ul class="nav nav-pills pills-zan"> <li class="active"><a href="#sidebar-hot" data-toggle="tab"><?php echo $title1; ?> </a></li> <li><a href="#sidebar-new" data-toggle="tab"><?php echo $title2; ?> </a></li> <li><a href="#sidebar-rand" data-toggle="tab"><?php echo $title3; ?> </a></li> </ul> <div class="tab-content"> <div class="tab-pane active nav bs-sidenav fade in" id="sidebar-hot"> <ul class="list-group"> <?php // 设置全局变量,实现post整体赋值 global $post; $posts = zan_get_hotest_posts($num); foreach ($posts as $post) { setup_postdata($post); ?> <li class="list-group-item clearfix"> <a href="<?php the_permalink(); ?> "> <?php the_title(); ?> </a> <span class="badge"> <?php if (function_exists('the_views')) { the_views(); } ?> </span> </li> <?php } wp_reset_postdata(); ?> </ul> </div> <div class="tab-pane fade" id="sidebar-new"> <ul class="list-group"> <?php // 设置全局变量,实现post整体赋值 global $post; $posts = zan_get_latest_posts($num); foreach ($posts as $post) { setup_postdata($post); ?> <li class="list-group-item clearfix"> <a href="<?php the_permalink(); ?> "> <?php the_title(); ?> </a> <span class="badge"> <?php if (function_exists('the_views')) { the_views(); } ?> </span> </li> <?php } wp_reset_postdata(); ?> </ul> </div> <div class="tab-pane nav bs-sidenav fade" id="sidebar-rand"> <ul class="list-group"> <?php // 设置全局变量,实现post整体赋值 global $post; $posts = zan_get_rand_posts($num); foreach ($posts as $post) { setup_postdata($post); ?> <li class="list-group-item clearfix"> <a href="<?php the_permalink(); ?> "> <?php the_title(); ?> </a> <span class="badge"> <?php if (function_exists('the_views')) { the_views(); } ?> </span> </li> <?php } wp_reset_postdata(); ?> </ul> </div> </div> </div> <?php echo $after_widget; }