LLMS_Shortcodes::memberships( array $atts )
Memberships Shortcode
Description Description
Used for shortcode [lifterlms_memberships].
Parameters Parameters
- $atts
-
(array) (Required) Associative array of shortcode attributes.
Return Return
(string)
Source Source
File: includes/shortcodes/class.llms.shortcodes.php
*/ public static function memberships( $atts ) { // Enqueue match height so the loop isn't all messed up visually. self::enqueue_script( 'llms-jquery-matchheight' ); if ( isset( $atts['category'] ) ) { $tax = array( array( 'taxonomy' => 'membership_cat', 'field' => 'slug', 'terms' => $atts['category'], ), ); } $args = array( 'paged' => is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' ), 'post_type' => 'llms_membership', 'post_status' => 'publish', 'posts_per_page' => isset( $atts['posts_per_page'] ) ? $atts['posts_per_page'] : -1, 'order' => isset( $atts['order'] ) ? $atts['order'] : 'ASC', 'orderby' => isset( $atts['orderby'] ) ? $atts['orderby'] : 'title', 'tax_query' => isset( $tax ) ? $tax : '', ); if ( isset( $atts['id'] ) ) { $args['p'] = $atts['id']; } $query = new WP_Query( $args ); ob_start(); if ( $query->have_posts() ) : /** * lifterlms_before_loop hook * * @hooked lifterlms_loop_start - 10 */ do_action( 'lifterlms_before_loop' ); while ( $query->have_posts() ) : $query->the_post(); llms_get_template_part( 'loop/content', get_post_type() ); endwhile; /** * lifterlms_before_loop hook * * @hooked lifterlms_loop_end - 10 */ do_action( 'lifterlms_after_loop' ); echo '<nav class="llms-pagination">'; echo paginate_links( array( 'base' => str_replace( 999999, '%#%', esc_url( get_pagenum_link( 999999 ) ) ), 'format' => '?page=%#%', 'total' => $query->max_num_pages, 'current' => max( 1, $args['paged'] ), 'prev_next' => true, 'prev_text' => '«' . __( 'Previous', 'lifterlms' ), 'next_text' => __( 'Next', 'lifterlms' ) . '»', 'type' => 'list', ) ); echo '</nav>'; else : llms_get_template( 'loop/none-found.php' ); endif; wp_reset_postdata(); return ob_get_clean();
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
4.12.0 | Handle pagination when the shortcode is used on the static front page. |
3.0.2 | |
1.4.4 | Introduced. |