WordPress.org

Ready to get started?Download WordPress

Forums

Display Posts Shortcode
[resolved] pagination (15 posts)

  1. mrhayduke
    Member
    Posted 2 years ago #

    Hello. I've used this plugin on a site in development and works great and well documented. Thank you.

    Wondering if you have any thoughts about if/how one could use pagination when there are a lot of results. I know we can use posts_per_page=-1 to list all posts but if there are a lot (20, 30, 40, etc.) it gets to be an unwieldy page.

    Thanks.

    Ted

    http://wordpress.org/extend/plugins/display-posts-shortcode/

  2. Bill Erickson
    Member
    Plugin Author

    Posted 2 years ago #

    The problem with pagination is that it would interfere with the query of the current page. If you have a multi-page article and you use the display posts shortcode with pagination, clicking "Next" will show the next results AND change the page content.

    If you need pagination, it's really best to customize the main WordPress query.

  3. mrhayduke
    Member
    Posted 2 years ago #

    Thanks, Bill. I realize pagination isn't something the plugin (which is great, btw) is intended to tackle. Appreciate the reply!

  4. kjparish
    Member
    Posted 2 years ago #

    I've gotten this plugin to work with pagination using WP-Page Navi, but you need to feel comfortable tweaking the plugin itself. I installed WP Page Navi and dropped in much of the code from this blog post: and it works!

  5. Jack (wpforchurch)
    Member
    Posted 2 years ago #

    Would you be so kind as to post what changes you made to the plugin? Did you add code from WP Page Navi or just install the plugin?

    Thanks!

  6. designblogg
    Member
    Posted 2 years ago #

    Yea would like to know how you did it aswell

  7. kjparish
    Member
    Posted 2 years ago #

    So, it's been a little while now since I set this up, but here's what I did (which worked):

    You need to open the display-posts-shortcode.php file in the plugin folder. Find the // Set up initial query for post // section. This is where you'll be adding to the existing code and inserting the query that allows for pagination (this is a copy of what I created before the "// If Post IDs" section).

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Next - you need to add pagenavi. I inserted it after the 'endwhile;' like so:

    endwhile;
    wp_pagenavi( array( 'query' => $listing ) );
       wp_reset_query();

    I'm no expert at this stuff, but I was able to hack a bit to get this working. I hope this helps you.

  8. Leiif
    Member
    Posted 2 years ago #

    Where's the code? I see the part about pagenavi.

  9. Leiif
    Member
    Posted 2 years ago #

    My question has been resolved. I found a work around with the Advanced Excerpts plugin.

  10. fruitshakes
    Member
    Posted 2 years ago #

    Haven't seen any resolutions? How come it was resolved?
    Any workaround yet?
    Thanks.

  11. kjparish
    Member
    Posted 2 years ago #

    Did not realize my code snippet above had been chopped off some time ago. Here it is again. Hope this helps.

    // Set up initial query for post
    	$args = array(
    		'post_type' => $post_type,
    		'tag' => $tag,
    		'category_name' => $category,
    		'posts_per_page' => $posts_per_page,
    		'order' => $order,
    		'orderby' => $orderby,
    
    	);
    
    if( get_query_var( 'paged' ) )
    	$my_page = get_query_var( 'paged' );
    else {
    	if( get_query_var( 'page' ) )
    		$my_page = get_query_var( 'page' );
    	else
    		$my_page = 1;
    	set_query_var( 'paged', $my_page );
    	$paged = $my_page;
    }
    
    // default loop here, if applicable, followed by wp_reset_query();
    
    $args = array(
    	// other query params here,
    	'paged' => $my_page
    );
  12. Leiif
    Member
    Posted 2 years ago #

    In regard to "fruitshakes" and my post.
    "My question has been resolved. I found a work around with the Advanced Excerpts plugin."

    I am not using this plugin as I found a better solution with "Advanced Excerpts"

  13. fruitshakes
    Member
    Posted 2 years ago #

    Leiif,

    Will celebrate if you share your workaround on Advanced Exerpts for pagination.

  14. tennyy
    Member
    Posted 1 year ago #

    kjparish,

    When I try this, it will show all categories in my list even I only set one category, how can I fix it?

    meanwhile, can I move the pagination to the bottom?

    Thanks!

  15. Leiif
    Member
    Posted 1 year ago #

    Hi fruitshakes,

    Sorry I didn't get notice of your post but just got one for the last post by tennyy. I wanted my category pages to show more than just the basic excerpt and using "Advanced Excerpts" was what worked for me. I use my categories as navigational aids to getting to specific types of posts. Not sure what you are after.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic