Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( ! function_exists( 'custom_jnews_popular_post_lists_shortcode' ) ) {
- /**
- * Render popular post list based on selected query sort.
- *
- * Usage: [custom_jnews_popular_post_lists sortBy="popular_post_day" limit="4"]
- *
- * @param array $atts Shortcode attributes.
- *
- * @return string
- */
- function custom_jnews_popular_post_lists_shortcode( $atts ) {
- $atts = shortcode_atts(
- array(
- 'sortby' => 'popular_post_day',
- 'limit' => 4,
- ),
- array_change_key_case( (array) $atts, CASE_LOWER ),
- 'custom_jnews_popular_post_lists'
- );
- $valid_value = array( 'popular_post_day', 'popular_post_week', 'popular_post_month', 'popular_post' );
- $sort_by = sanitize_key( $atts['sortby'] );
- $sort_by = in_array( $sort_by, $valid_value, true ) ? $sort_by : 'popular_post_day';
- $limit = max( 1, absint( $atts['limit'] ) );
- $output = '';
- $output .= '<div class="custom-popular-posts-lists">';
- $widget = new \JNews\Widget\Normal\Element\TabPostWidget();
- if ( function_exists( 'jnews_view_counter_query' ) ) {
- $results = \JNews\Module\ModuleQuery::do_query(
- array(
- 'post_type' => 'post',
- 'sort_by' => $sort_by,
- 'post_offset' => 0,
- 'number_post' => $limit,
- 'pagination_number_post' => $limit,
- )
- );
- if ( isset( $results['result'] ) ) {
- $output .= $widget->trending_content( $results['result'] );
- }
- }
- $output .= '</div>';
- return jnews_sanitize_output( $output );
- }
- }
- add_shortcode( 'custom_jnews_popular_post_lists', 'custom_jnews_popular_post_lists_shortcode' );
Advertisement
Add Comment
Please, Sign In to add comment