shikh
Forum Replies Created
-
Forum: Plugins
In reply to: [WP Shortcodes Plugin — Shortcodes Ultimate] Pagination not workingHere is how function posts() looks for me in inc/core/shortcodes.php now:
public static function posts( $atts = null, $content = null ) { // Prepare error var $error = null; // Parse attributes $atts = shortcode_atts( array( 'template' => 'templates/default-loop.php', 'id' => false, 'posts_per_page' => get_option( 'posts_per_page' ), 'post_type' => 'post', 'taxonomy' => 'category', 'tax_term' => false, 'tax_operator' => 'IN', 'author' => '', 'tag' => '', 'meta_key' => '', 'offset' => 0, 'order' => 'DESC', 'orderby' => 'date', 'post_parent' => false, 'post_status' => 'publish', 'ignore_sticky_posts' => 'no' ), $atts, 'posts' ); $original_atts = $atts; $author = sanitize_text_field( $atts['author'] ); $id = $atts['id']; // Sanitized later as an array of integers $ignore_sticky_posts = ( bool ) ( $atts['ignore_sticky_posts'] === 'yes' ) ? true : false; $meta_key = sanitize_text_field( $atts['meta_key'] ); $offset = intval( $atts['offset'] ); $order = sanitize_key( $atts['order'] ); $orderby = sanitize_key( $atts['orderby'] ); $post_parent = $atts['post_parent']; $post_status = $atts['post_status']; $post_type = sanitize_text_field( $atts['post_type'] ); $posts_per_page = intval( $atts['posts_per_page'] ); $tag = sanitize_text_field( $atts['tag'] ); $tax_operator = $atts['tax_operator']; $tax_term = sanitize_text_field( $atts['tax_term'] ); $taxonomy = sanitize_key( $atts['taxonomy'] ); // Set up initial query for post $args = array( 'category_name' => '', 'order' => $order, 'orderby' => $orderby, 'post_type' => explode( ',', $post_type ), 'posts_per_page' => $posts_per_page, 'paged' => get_query_var('paged') ? get_query_var('paged') : 1, 'tag' => $tag ); // Ignore Sticky Posts if ( $ignore_sticky_posts ) $args['ignore_sticky_posts'] = true; // Meta key (for ordering) if ( !empty( $meta_key ) ) $args['meta_key'] = $meta_key; // If Post IDs if ( $id ) { $posts_in = array_map( 'intval', explode( ',', $id ) ); $args['post__in'] = $posts_in; } // Post Author if ( !empty( $author ) ) $args['author'] = $author; // Offset if ( !empty( $offset ) ) $args['offset'] = $offset; // Post Status $post_status = explode( ', ', $post_status ); $validated = array(); $available = array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash', 'any' ); foreach ( $post_status as $unvalidated ) { if ( in_array( $unvalidated, $available ) ) $validated[] = $unvalidated; } if ( !empty( $validated ) ) $args['post_status'] = $validated; // If taxonomy attributes, create a taxonomy query if ( !empty( $taxonomy ) && !empty( $tax_term ) ) { // Term string to array $tax_term = explode( ',', $tax_term ); // Validate operator if ( !in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) ) $tax_operator = 'IN'; $tax_args = array( 'tax_query' => array( array( 'taxonomy' => $taxonomy, 'field' => ( is_numeric( $tax_term[0] ) ) ? 'id' : 'slug', 'terms' => $tax_term, 'operator' => $tax_operator ) ) ); // Check for multiple taxonomy queries $count = 2; $more_tax_queries = false; while ( isset( $original_atts['taxonomy_' . $count] ) && !empty( $original_atts['taxonomy_' . $count] ) && isset( $original_atts['tax_' . $count . '_term'] ) && !empty( $original_atts['tax_' . $count . '_term'] ) ) { // Sanitize values $more_tax_queries = true; $taxonomy = sanitize_key( $original_atts['taxonomy_' . $count] ); $terms = explode( ', ', sanitize_text_field( $original_atts['tax_' . $count . '_term'] ) ); $tax_operator = isset( $original_atts['tax_' . $count . '_operator'] ) ? $original_atts[ 'tax_' . $count . '_operator'] : 'IN'; $tax_operator = in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) ? $tax_operator : 'IN'; $tax_args['tax_query'][] = array( 'taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $terms, 'operator' => $tax_operator ); $count++; } if ( $more_tax_queries ): $tax_relation = 'AND'; if ( isset( $original_atts['tax_relation'] ) && in_array( $original_atts['tax_relation'], array( 'AND', 'OR' ) ) ) $tax_relation = $original_atts['tax_relation']; $args['tax_query']['relation'] = $tax_relation; endif; $args = array_merge( $args, $tax_args ); } // If post parent attribute, set up parent if ( $post_parent ) { if ( 'current' == $post_parent ) { global $post; $post_parent = $post->ID; } $args['post_parent'] = intval( $post_parent ); } // Save original posts global $posts; $original_posts = $posts; // Query posts $posts = new WP_Query( $args ); $GLOBALS['wp_query'] = $posts; // Buffer output ob_start(); // Search for template in stylesheet directory if ( file_exists( STYLESHEETPATH . '/' . $atts['template'] ) ) load_template( STYLESHEETPATH . '/' . $atts['template'], false ); // Search for template in theme directory elseif ( file_exists( TEMPLATEPATH . '/' . $atts['template'] ) ) load_template( TEMPLATEPATH . '/' . $atts['template'], false ); // Search for template in plugin directory elseif ( path_join( dirname( SU_PLUGIN_FILE ), $atts['template'] ) ) load_template( path_join( dirname( SU_PLUGIN_FILE ), $atts['template'] ), false ); // Template not found else echo Su_Tools::error( __FUNCTION__, __( 'template not found', 'su' ) ); $output = ob_get_contents(); ob_end_clean(); // Return original posts $posts = $original_posts; // Reset the query wp_reset_query(); wp_reset_postdata(); su_query_asset( 'css', 'su-other-shortcodes' ); return $output; }
as for the template change, there’s nothing more than putting
posts_nav_link()
wherever you want the pagination to appearForum: Plugins
In reply to: [WP Shortcodes Plugin — Shortcodes Ultimate] Pagination not working(copy of my reply to the same question in another thread)
Just faced with the same question.
Quick searching over internet showed there’s no known solution (at least that I could find).
I looked into the plugin and was able to tune it to show the pagination.
I think I will leave the solution here just in case someone will be searching for the same in the future (unless the plugin is upgraded to embed the solution).
NB: The solution requires basic knowledge of PHP and WordPress architecture, since it includes plugin source code adjustment.
NB2: The solution describes an unconditional pagination inclusion. If you need to be able to switch pagination on / off, elaborate the solution further.there are two steps required to achieve the goal:
a) adjust WP variables to turn standard pagination workflow on
b) adjust page template to display paginationOk now, here are the modifications (based on plugin version 4.9.3)
1) in file inc/core/shortcodes.php, in function posts(), add the following line
$GLOBALS[‘wp_query’] = $posts;
after the initialization of the $posts variable ($posts = new WP_Query( $args ))
this will setup WP global variable wp_query used in standard pagination generation functions.
2) same function, add
wp_reset_query();
line before this call: wp_reset_postdata()
this will reset the above modification after the pagination is printed
3) same function, find the $atts array initialization in the very beginning and ‘paged’ argument to the initialization array:
‘paged’ => get_query_var(‘paged’) ? get_query_var(‘paged’) : 1
this will tell the query current page index to display
4) add pagination output to the templates/default-loop.php file (or the other template you are using). You can use standard WP functions for that (function posts_nav_link(), I added it to the end of the template).Hope this wasn’t too complicated ??
Forum: Plugins
In reply to: [WP Shortcodes Plugin — Shortcodes Ultimate] Posts pagination(copy of my reply to the same question in another thread)
Just faced with the same question.
Quick searching over internet showed there’s no known solution (at least that I could find).
I looked into the plugin and was able to tune it to show the pagination.
I think I will leave the solution here just in case someone will be searching for the same in the future (unless the plugin is upgraded to embed the solution).
NB: The solution requires basic knowledge of PHP and WordPress architecture, since it includes plugin source code adjustment.
NB2: The solution describes an unconditional pagination inclusion. If you need to be able to switch pagination on / off, elaborate the solution further.there are two steps required to achieve the goal:
a) adjust WP variables to turn standard pagination workflow on
b) adjust page template to display paginationOk now, here are the modifications (based on plugin version 4.9.3)
1) in file inc/core/shortcodes.php, in function posts(), add the following line
$GLOBALS[‘wp_query’] = $posts;
after the initialization of the $posts variable ($posts = new WP_Query( $args ))
this will setup WP global variable wp_query used in standard pagination generation functions.
2) same function, add
wp_reset_query();
line before this call: wp_reset_postdata()
this will reset the above modification after the pagination is printed
3) same function, find the $atts array initialization in the very beginning and ‘paged’ argument to the initialization array:
‘paged’ => get_query_var(‘paged’) ? get_query_var(‘paged’) : 1
this will tell the query current page index to display
4) add pagination output to the templates/default-loop.php file (or the other template you are using). You can use standard WP functions for that (function posts_nav_link(), I added it to the end of the template).Hope this wasn’t too complicated ??
Forum: Plugins
In reply to: [WP Shortcodes Plugin — Shortcodes Ultimate] PaginationJust faced with the same question.
Quick searching over internet showed there’s no known solution (at least that I could find).
I looked into the plugin and was able to tune it to show the pagination.
I think I will leave the solution here just in case someone will be searching for the same in the future (unless the plugin is upgraded to embed the solution).
NB: The solution requires basic knowledge of PHP and WordPress architecture, since it includes plugin source code adjustment.
NB2: The solution describes an unconditional pagination inclusion. If you need to be able to switch pagination on / off, elaborate the solution further.there are two steps required to achieve the goal:
a) adjust WP variables to turn standard pagination workflow on
b) adjust page template to display paginationOk now, here are the modifications (based on plugin version 4.9.3)
1) in file inc/core/shortcodes.php, in function posts(), add the following line
$GLOBALS[‘wp_query’] = $posts;
after the initialization of the $posts variable ($posts = new WP_Query( $args ))
this will setup WP global variable wp_query used in standard pagination generation functions.
2) same function, add
wp_reset_query();
line before this call: wp_reset_postdata()
this will reset the above modification after the pagination is printed
3) same function, find the $atts array initialization in the very beginning and ‘paged’ argument to the initialization array:
‘paged’ => get_query_var(‘paged’) ? get_query_var(‘paged’) : 1
this will tell the query current page index to display
4) add pagination output to the templates/default-loop.php file (or the other template you are using). You can use standard WP functions for that (function posts_nav_link(), I added it to the end of the template).Hope this wasn’t too complicated ??