GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-widget-page-links.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * Widget to display page links
5  *
6  * @extends GravityView_Widget
7  */
9 
10  public $icon = 'dashicons-controls-forward';
11 
12  protected $show_on_single = false;
13 
14  function __construct() {
15 
16  $this->widget_description = __('Links to multiple pages of results.', 'gk-gravityview' );
17 
18  $default_values = array( 'header' => 1, 'footer' => 1 );
19  $settings = array( 'show_all' => array(
20  'type' => 'checkbox',
21  'label' => __( 'Show each page number', 'gk-gravityview' ),
22  'desc' => __('Show every page number instead of summary (eg: 1 2 3 ... 8 ยป)', 'gk-gravityview'),
23  'value' => false
24  ));
25  parent::__construct( __( 'Page Links', 'gk-gravityview' ) , 'page_links', $default_values, $settings );
26 
27  }
28 
29  public function render_frontend( $widget_args, $content = '', $context = '') {
31 
32  if( !$this->pre_render_frontend() ) {
33  return;
34  }
35 
36  $atts = shortcode_atts( array(
37  'page_size' => \GV\Utils::get( $gravityview_view->paging, 'page_size' ),
38  'total' => $gravityview_view->total_entries,
39  'show_all' => !empty( $this->settings['show_all']['default'] ),
40  'current' => (int) \GV\Utils::_GET( 'pagenum', 1 ),
41  ), $widget_args, 'gravityview_widget_page_links' );
42 
43  $page_link_args = array(
44  'base' => add_query_arg('pagenum','%#%', gv_directory_link() ),
45  'format' => '&pagenum=%#%',
46  'add_args' => array(), //
47  'prev_text' => '&laquo;',
48  'next_text' => '&raquo;',
49  'type' => 'list',
50  'end_size' => 1,
51  'mid_size' => 2,
52  'total' => empty( $atts['page_size'] ) ? 0 : ceil( $atts['total'] / $atts['page_size'] ),
53  'current' => $atts['current'],
54  'show_all' => !empty( $atts['show_all'] ), // to be available at backoffice
55  );
56 
57  /**
58  * @filter `gravityview_page_links_args` Filter the pagination options
59  * @since 1.1.4
60  * @param array $page_link_args Array of arguments for the `paginate_links()` function. [Read more about `paginate_links()`](http://developer.wordpress.org/reference/functions/paginate_links/)
61  */
62  $page_link_args = apply_filters('gravityview_page_links_args', $page_link_args );
63 
64  $page_links = paginate_links( $page_link_args );
65 
66  if( !empty( $page_links )) {
67  $class = !empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : '';
68  $class = gravityview_sanitize_html_class( 'gv-widget-page-links ' . $class );
69  echo '<div class="'.$class.'">'. $page_links .'</div>';
70  } else {
71  gravityview()->log->debug( 'No page links; paginate_links() returned empty response.' );
72  }
73 
74  }
75 
76 }
77 
static getInstance( $passed_post=NULL)
gv_directory_link( $post=NULL, $add_pagination=true, $context=null)
Definition: class-api.php:934
pre_render_frontend()
General validations when rendering the widget.
$class
If this file is called directly, abort.
if(empty( $field_settings['content'])) $content
Definition: custom.php:37
gravityview()
The main GravityView wrapper function.