Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( ! function_exists( 'jnews_trending_tabpost_widget_shortcode' ) ) {
- /**
- * Render tab post widget with trending content for 24 hours, 7 days, and 30 days.
- *
- * Usage: [custom_jnews_trending_tabpost_widget title="Trending" limit="4"]
- *
- * @param array $atts Shortcode attributes.
- *
- * @return string
- */
- function jnews_trending_tabpost_widget_shortcode( $atts ) {
- $atts = shortcode_atts(
- array(
- 'title' => '',
- 'limit' => 4,
- ),
- $atts,
- 'custom_jnews_trending_tabpost_widget'
- );
- $limit = max( 1, absint( $atts['limit'] ) );
- $widget = new \JNews\Widget\Normal\Element\TabPostWidget();
- $tabs = array(
- array(
- 'id' => 'jeg_tabpost_1',
- 'label' => esc_html__( '24 hour', 'jnews' ),
- 'sort_by' => 'popular_post_day',
- 'active' => true,
- ),
- array(
- 'id' => 'jeg_tabpost_2',
- 'label' => esc_html__( '7 Days', 'jnews' ),
- 'sort_by' => 'popular_post_week',
- 'active' => false,
- ),
- array(
- 'id' => 'jeg_tabpost_3',
- 'label' => esc_html__( '30 Days', 'jnews' ),
- 'sort_by' => 'popular_post_month',
- 'active' => false,
- ),
- );
- $output = '';
- $output .= '<div class="jeg_tabpost_widget">';
- if ( ! function_exists( 'JNews_View_Counter' ) ) {
- $output .=
- '<div class="alert alert-error">
- <strong>' . esc_html__( 'Plugin Install', 'jnews' ) . '</strong>' . ' : ' . esc_html__( 'Widget Tab Post needs JNews - View Counter to be installed', 'jnews' ) .
- '</div>';
- }
- $output .= '<ul class="jeg_tabpost_nav tab-3">';
- foreach ( $tabs as $tab ) {
- $output .= '<li data-tab-content="' . esc_attr( $tab['id'] ) . '"' . ( $tab['active'] ? ' class="active"' : '' ) . '>' . esc_html( $tab['label'] ) . '</li>';
- }
- $output .= '</ul>';
- $output .= '<div class="jeg_tabpost_content">';
- foreach ( $tabs as $tab ) {
- $output .= '<div class="jeg_tabpost_item' . ( $tab['active'] ? ' active' : '' ) . '" id="' . esc_attr( $tab['id'] ) . '"><div class="jegwidgetpopular">';
- if ( function_exists( 'jnews_view_counter_query' ) ) {
- $results = \JNews\Module\ModuleQuery::do_query(
- array(
- 'post_type' => 'post',
- 'sort_by' => $tab['sort_by'],
- 'post_offset' => 0,
- 'number_post' => $limit,
- 'pagination_number_post' => $limit,
- )
- );
- $output .= $widget->trending_content( $results['result'] );
- }
- $output .= '</div></div>';
- }
- $output .= '</div></div>';
- return jnews_sanitize_output( $output );
- }
- }
- add_shortcode( 'custom_jnews_trending_tabpost_widget', 'jnews_trending_tabpost_widget_shortcode' );
Advertisement
Add Comment
Please, Sign In to add comment