arie_cristianD

add tab post custom shortcode

Jun 14th, 2026
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.66 KB | None | 0 0
  1. if ( ! function_exists( 'jnews_trending_tabpost_widget_shortcode' ) ) {
  2.     /**
  3.      * Render tab post widget with trending content for 24 hours, 7 days, and 30 days.
  4.      *
  5.      * Usage: [custom_jnews_trending_tabpost_widget title="Trending" limit="4"]
  6.      *
  7.      * @param array $atts Shortcode attributes.
  8.      *
  9.      * @return string
  10.      */
  11.     function jnews_trending_tabpost_widget_shortcode( $atts ) {
  12.         $atts = shortcode_atts(
  13.             array(
  14.                 'title' => '',
  15.                 'limit' => 4,
  16.             ),
  17.             $atts,
  18.             'custom_jnews_trending_tabpost_widget'
  19.         );
  20.  
  21.         $limit  = max( 1, absint( $atts['limit'] ) );
  22.         $widget = new \JNews\Widget\Normal\Element\TabPostWidget();
  23.         $tabs   = array(
  24.             array(
  25.                 'id'      => 'jeg_tabpost_1',
  26.                 'label'   => esc_html__( '24 hour', 'jnews' ),
  27.                 'sort_by' => 'popular_post_day',
  28.                 'active'  => true,
  29.             ),
  30.             array(
  31.                 'id'      => 'jeg_tabpost_2',
  32.                 'label'   => esc_html__( '7 Days', 'jnews' ),
  33.                 'sort_by' => 'popular_post_week',
  34.                 'active'  => false,
  35.             ),
  36.             array(
  37.                 'id'      => 'jeg_tabpost_3',
  38.                 'label'   => esc_html__( '30 Days', 'jnews' ),
  39.                 'sort_by' => 'popular_post_month',
  40.                 'active'  => false,
  41.             ),
  42.         );
  43.  
  44.         $output = '';
  45.  
  46.         $output .= '<div class="jeg_tabpost_widget">';
  47.  
  48.         if ( ! function_exists( 'JNews_View_Counter' ) ) {
  49.             $output .=
  50.                 '<div class="alert alert-error">
  51.                     <strong>' . esc_html__( 'Plugin Install', 'jnews' ) . '</strong>' . ' : ' . esc_html__( 'Widget Tab Post needs JNews - View Counter to be installed', 'jnews' ) .
  52.                 '</div>';
  53.         }
  54.  
  55.         $output .= '<ul class="jeg_tabpost_nav tab-3">';
  56.         foreach ( $tabs as $tab ) {
  57.             $output .= '<li data-tab-content="' . esc_attr( $tab['id'] ) . '"' . ( $tab['active'] ? ' class="active"' : '' ) . '>' . esc_html( $tab['label'] ) . '</li>';
  58.         }
  59.         $output .= '</ul>';
  60.  
  61.         $output .= '<div class="jeg_tabpost_content">';
  62.         foreach ( $tabs as $tab ) {
  63.             $output .= '<div class="jeg_tabpost_item' . ( $tab['active'] ? ' active' : '' ) . '" id="' . esc_attr( $tab['id'] ) . '"><div class="jegwidgetpopular">';
  64.  
  65.             if ( function_exists( 'jnews_view_counter_query' ) ) {
  66.                 $results = \JNews\Module\ModuleQuery::do_query(
  67.                     array(
  68.                         'post_type'              => 'post',
  69.                         'sort_by'                => $tab['sort_by'],
  70.                         'post_offset'            => 0,
  71.                         'number_post'            => $limit,
  72.                         'pagination_number_post' => $limit,
  73.                     )
  74.                 );
  75.  
  76.                 $output .= $widget->trending_content( $results['result'] );
  77.             }
  78.  
  79.             $output .= '</div></div>';
  80.         }
  81.         $output .= '</div></div>';
  82.  
  83.         return jnews_sanitize_output( $output );
  84.     }
  85. }
  86.  
  87. add_shortcode( 'custom_jnews_trending_tabpost_widget', 'jnews_trending_tabpost_widget_shortcode' );
  88.  
Advertisement
Add Comment
Please, Sign In to add comment