GravityView  1.19.4
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  protected $show_on_single = false;
11 
12  function __construct() {
13 
14  $this->widget_description = __('Links to multiple pages of results.', 'gravityview' );
15 
16  $default_values = array( 'header' => 1, 'footer' => 1 );
17  $settings = array( 'show_all' => array(
18  'type' => 'checkbox',
19  'label' => __( 'Show each page number', 'gravityview' ),
20  'desc' => __('Show every page number instead of summary (eg: 1 2 3 ... 8 ยป)', 'gravityview'),
21  'value' => false
22  ));
23  parent::__construct( __( 'Page Links', 'gravityview' ) , 'page_links', $default_values, $settings );
24 
25  }
26 
27  public function render_frontend( $widget_args, $content = '', $context = '') {
29 
30  if( !$this->pre_render_frontend() ) {
31  return;
32  }
33 
34  $atts = shortcode_atts( array(
35  'page_size' => rgar( $gravityview_view->paging, 'page_size' ),
36  'total' => $gravityview_view->total_entries,
37  'show_all' => !empty( $this->settings['show_all']['default'] ),
38  'current' => (int) rgar( $_GET, 'pagenum', 1 ),
39  ), $widget_args, 'gravityview_widget_page_links' );
40 
41  $page_link_args = array(
42  'base' => add_query_arg('pagenum','%#%', gv_directory_link() ),
43  'format' => '&pagenum=%#%',
44  'add_args' => array(), //
45  'prev_text' => '&laquo;',
46  'next_text' => '&raquo;',
47  'type' => 'list',
48  'end_size' => 1,
49  'mid_size' => 2,
50  'total' => empty( $atts['page_size'] ) ? 0 : ceil( $atts['total'] / $atts['page_size'] ),
51  'current' => $atts['current'],
52  'show_all' => !empty( $atts['show_all'] ), // to be available at backoffice
53  );
54 
55  /**
56  * @filter `gravityview_page_links_args` Filter the pagination options
57  * @since 1.1.4
58  * @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/)
59  */
60  $page_link_args = apply_filters('gravityview_page_links_args', $page_link_args );
61 
62  $page_links = paginate_links( $page_link_args );
63 
64  if( !empty( $page_links )) {
65  $class = !empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : '';
66  $class = gravityview_sanitize_html_class( 'gv-widget-page-links ' . $class );
67  echo '<div class="'.$class.'">'. $page_links .'</div>';
68  } else {
69  do_action( 'gravityview_log_debug', 'GravityView_Widget_Page_Links[render_frontend] No page links; paginate_links() returned empty response.' );
70  }
71 
72  }
73 
74 }
75 
Main GravityView widget class.
gv_directory_link($post=NULL, $add_pagination=true)
Definition: class-api.php:797
$class
pre_render_frontend()
General validations when rendering the widget.
static getInstance($passed_post=NULL)
if(empty($field_settings['content'])) $content
Definition: custom.php:37