$options['gapp_totalpost'] ), $atts, 'foundry_top_posts' ); if ($attr['total_post'] == ""){ $tot = $options['gapp_totalpost']; } else { $tot = $attr['total_post']; } $args = array( 'post_type' => 'post', 'orderby' => 'meta_value_num', 'meta_key' => '_gapp_post_views', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'posts_per_page' => $tot ); $the_query = new WP_Query( $args ); $gapp_onoffswitch = $options['gapp_onoffswitch']; if($gapp_onoffswitch == "1") { if ( $the_query->have_posts() ){ echo '
'; while ( $the_query->have_posts() ) { $the_query->the_post(); $feat_image = wp_get_attachment_url( get_post_thumbnail_id() ); if($feat_image != ''){ echo '
'.get_the_title().'
'; //echo '
'.get_the_title().' ('.get_the_ID().')
'; } } echo '
'; } } wp_reset_postdata(); } add_shortcode('gapp_get_latest', 'gapp_get_latest_function'); /* Shortcode For grid */ function gapp_get_latest_grid_function($atts){ $options = gapp_options(); $attr = shortcode_atts( array( 'total_post' => $options['gapp_totalpost_grid'] ), $atts, 'foundry_top_posts' ); if ($attr['total_post'] == ""){ $tot = $options['gapp_totalpost_grid']; } else { $tot = $attr['total_post']; } $args = array( 'post_type' => 'post', 'orderby' => 'meta_value_num', 'meta_key' => '_gapp_post_views', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'posts_per_page' => $tot ); $result = ''; $the_query = new WP_Query( $args ); $gapp_onoffswitch_grid = $options['gapp_onoffswitch_grid']; if($gapp_onoffswitch_grid == "1") { if ( $the_query->have_posts() ){ $result .= '
'; while ( $the_query->have_posts() ) { $the_query->the_post(); $feat_image = wp_get_attachment_url( get_post_thumbnail_id() ); if($feat_image != ''){ $result .= '
'.get_the_title().'
'.get_the_title().'

'.get_the_excerpt().'

'; //echo '
'.get_the_title().' ('.get_the_ID().')
'; } } $result .= '
'; } return $result; } wp_reset_postdata(); } add_shortcode('gapp_get_latest_grid', 'gapp_get_latest_grid_function'); function Gapp_widget_enqueue_script() { wp_enqueue_style('bxslider', plugin_dir_url( __FILE__ ) . 'css/jquery.bxslider.css'); wp_enqueue_style('bootstrap', plugin_dir_url( __FILE__ ) . 'css/bootstrap.min.css'); wp_enqueue_style('custom', plugin_dir_url( __FILE__ ) . 'css/custom.css'); wp_enqueue_script( 'bxslider-js', plugin_dir_url( __FILE__ ) . 'js/jquery.bxslider.min.js', array('jquery'), '', true ); wp_enqueue_script( 'custom', plugin_dir_url( __FILE__ ) . 'js/custom.js', array('bxslider-js'), '', true ); } add_action('wp_enqueue_scripts', 'Gapp_widget_enqueue_script'); class GappTopPostWidget extends WP_Widget { private $popPosts; /** * Sets up the widget * * @since 0.1 */ public function __construct() { parent::__construct( 'gd-analytic-top-posts', // Base ID __( 'Top Posts', 'largo' ), // Name array( 'description' => __( 'List Top posts', 'largo' ), ) // Args ); } /** * Output the widget * * * @param array $args * @param array $instance */ function widget( $args, $instance ) { extract( $args ); $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Recent ' . $posts_term, 'largo') : $instance['title'], $instance ); /* * Start drawing the widget */ echo $before_widget; if ( $title ) { echo $before_title . $title . $after_title; } $args = array( 'post_type' => 'post', 'orderby' => 'meta_value_num', 'meta_key' => '_gapp_post_views', 'orderby' => 'meta_value_num', 'order' => 'DESC', ); $num_posts = ( isset( $instance['num_posts'] ) && !empty( $instance['num_posts'] ) )? $instance['num_posts']: 5; if( isset( $num_posts ) && !empty( $num_posts ) && $num_posts > 1 ){ $args['posts_per_page'] = $num_posts; } $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ){ echo '
'; while ( $the_query->have_posts() ) { $the_query->the_post(); echo '
'; echo ''. get_the_title() .''; echo '
'; if (has_post_thumbnail( ) ){ echo get_the_post_thumbnail( get_the_ID(), array( 160, 100 ) ); } else{ $image = ''; echo ''; } echo '
'; echo '
'; } echo '
'; } wp_reset_postdata(); echo $after_widget; } /** * Outputs the options form on admin * * @param array $instance The widget options */ public function form( $instance ) { $defaults = array( 'title' => __('popular', 'largo'), 'num_posts' => 5, ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>