/** * Returns the next and previous posts pagination. * * @param int $total Total pages. * @param int $current The current page. * @return string The HTML output for the posts pagination. */ function tripp_next_previous_pagination( $total = 0, $current = 0 ) { if ( ! $current ) { $current = max( 1, get_query_var( 'paged' ) ); } $pagination = ''; // Previous link. if ( $current > 1 ) { $label = '' . esc_html__( 'Newer', 'tripp' ) . ''; $pagination = get_previous_posts_link( $label ); } // Current link. if ( $total > 1 ) { $pagination .= '' . esc_html( $current ) . ''; } // Next link. $nextpage = absint( $current ) + 1; if ( $nextpage <= $total ) { $label = '' . esc_html__( 'Older', 'tripp' ) . ''; $pagination .= get_next_posts_link( $label, $total ); } return $pagination; } /** * Retrieves a numbered pagination. * * @param array $args { * Optional. Default pagination arguments, see paginate_links(). * * @type string $screen_reader_text Screen reader text for navigation element. * Default 'Posts navigation'. * @type string $aria_label ARIA label text for the nav element. Default 'Posts'. * @type string $class Custom class for the nav element. Default 'pagination'. * } * @return string Markup for pagination links. */ function tripp_numbered_pagination( $args = array() ) { // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { $args['aria_label'] = $args['screen_reader_text']; } $args = wp_parse_args( $args, array( 'end_size' => 0, 'mid_size' => 1, 'prev_text' => sprintf( '%s', esc_html__( 'Newer', 'tripp' ) ), 'next_text' => sprintf( '%s', esc_html__( 'Older', 'tripp' ) ), ) ); // Make sure we get a string back. Plain is the next best thing. if ( isset( $args['type'] ) && 'array' === $args['type'] ) { $args['type'] = 'plain'; } // Set up paginated links. return paginate_links( $args ); } /** * Gets the pagination navigation. * * @param string $page_links The page links. * @param string $class The pagination class name. * @return string The HTML output for the posts pagination. */ function tripp_get_pagination( $page_links = '', $class = '' ) { if ( empty( $page_links ) ) { return ''; } $output = sprintf( '', $class, $page_links ); return $output; } /** * Returns the URL of the post page. * * @global WP_Rewrite $wp_rewrite * * @param int $i Page number. * @return string URL of the post page. */ function tripp_link_page_url( $i ) { global $wp_rewrite; $post = get_post(); $query_args = array(); if ( 1 === $i ) { $url = get_permalink(); } else { $permalink = get_option( 'permalink_structure' ); if ( empty( $permalink ) || in_array( $post->post_status, array( 'draft', 'pending' ), true ) ) { $url = add_query_arg( 'page', $i, get_permalink() ); } elseif ( 'page' === get_option( 'show_on_front' ) && absint( get_option( 'page_on_front' ) ) === $post->ID ) { $url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' ); } else { $url = trailingslashit( get_permalink() ) . user_trailingslashit( $i, 'single_paged' ); } } if ( is_preview() ) { if ( ( 'draft' !== $post->post_status ) && isset( $_GET['preview_id'], $_GET['preview_nonce'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $query_args['preview_id'] = absint( wp_unslash( $_GET['preview_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $query_args['preview_nonce'] = sanitize_key( $_GET['preview_nonce'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended } $url = get_preview_post_link( $post, $query_args, $url ); } return $url; } /** * Returns whether the footer can be displayed. * * @param int $id The post ID. * @return bool Whether the footer can be displayed. */ function tripp_has_footer( $id = 0 ) { if ( empty( $id ) ) { $id = tripp_get_page_id(); } return false === (bool) get_post_meta( $id, '_tripp_hide_footer', true ); } /** * Return whether the footer gap is visible. * * @param int $id The post ID. * @return bool Whether the footer gap is visible. */ function tripp_has_footer_gap( $id = 0 ) { if ( ( is_archive() && ! is_post_type_archive() ) ) { return true; } if ( empty( $id ) ) { $id = tripp_get_page_id(); } return false === (bool) get_post_meta( $id, '_tripp_hide_footer_gap', true ); } /** * Determines if the Footer Logo can be displayed. * * @return bool Whether the Footer Logo can be displayed. */ function tripp_has_footer_logo() { return (bool) get_theme_mod( 'footer_logo', 0 ); } /** * Prints out the footer widgets class. * * @param string $class Space-separated string. * @param int $columns Number of columns. */ function tripp_footer_widgets_class( $class = '', $columns = 1 ) { $classes = array( $class ); if ( absint( $columns ) > 1 ) { $classes[] = "tripp-grid has-{$columns}-columns"; } else { $classes[] = 'has-one-column'; } echo esc_attr( implode( ' ', $classes ) ); } /** * Prints out the footer columns and widgets. * * @param int $columns Number of columns. */ function tripp_footer_columns( $columns = 1 ) { $is_preview = is_customize_preview(); $max = $is_preview ? 4 : $columns; for ( $i = 1; $i <= $max; $i++ ) { $name = 'footer-' . $i; $class = 'footer-col-' . esc_attr( $i ); if ( $is_preview && $i > $columns ) { $class .= ' is-hidden'; } echo '