This is because query_posts
resets the query. See this warning on the Codex page:
Pagination won’t work correctly, unless you use query_posts() in a
page template and you set the ‘paged’ query var appropriately:
http://scribu.net/wordpress/wp-pagenavi/right-way-to-use-query_posts.html
The call:
query_posts( 'category_name=category&showposts=2');
does not tell it which page to get (so it gets the first page). It’s a simple matter of:
$page = get_query_var('paged');
$page = (!empty($page) ? $page : 1);
query_posts( 'category_name=category&showposts=2&paged='.$page);
Note: For pages (i.e. when using a custom page template, you need to use get_query_var('page')
rather than get_query_var('paged')
.
Related Posts:
- Modify previous and next text from pagination links
- Rewriting search and pagination base
- WooCommerce – Customer Order History Pagination
- Getting rid of role=”navigation” in the Home Page Pagination
- Search not showing all results
- Custom Pagination is Broken
- Pagination on Custom Post
- Prev/Next Links Broken on Static Front Page Pagination
- Custom query vars filters problem with pagination
- How to add PHP pagination to wordpress
- Pagination 404 error(I have refreshed the permalinks and tried several previous options)
- How can I get my pagination loop to display the correct number of total pages?
- How to fix blank pagination links?
- Pagination not displaying
- /page/2/ redirect to 404
- Cleaning up WordPress to improve performance?
- How can I modify the permalink via a filter?
- wp_set_object_terms and arrays
- How to get the original price of the product in woocommerce?
- How to use WordPress (PHP) functions in AngularJS partials files?
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- How to add 2 posts under another post? Formatting should be intact
- Get widget settings function?
- enqueue multiple Google fonts with multiple weights and styles (italic)
- What is the fastest way to load PHP functions that are only used in one theme template?
- Adding tawk.to code just before body tag on functions.php file
- Can’t load WP function into external function
- Image as Sales Badge
- add_action shortcut?
- WSoD being caused by this piece of code
- How to Arrange PHP Files to Allow for Multiple Types of Pages?
- How to complete two other input fields, completed the first
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- Get page that displays all children of taxonomy parent
- Function to capture a value and store it in a variable
- My new button is in the wrong place
- Checking array against author id in loop
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Scrape external webpage for first image and add it to new post
- How do I link a button I created in theme customizer to a function?
- jQuery code not working when included in functions.php
- Fatal Errors on pluggable.php
- Log in / Log Out Custom Button
- Tell WP register script to load a script only when the entire page is loaded
- Can’t save php string to a custom field
- Limit Taxonomy Output in Conditional Statement
- wp_redirect only works on main site and not on other sites
- get_template_directory adding FTP root folders in urls
- Fatal error: Call to undefined function register_new_user()
- How to modify the default feed via a function
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- Loop over Array and get the distinct ids
- How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- Post not populating for custom post type based on category selection
- call_user_func_array() expects parameter 1 to be a valid callback, function ‘———-‘ not found or invalid function name
- How to remove the space before the ellipsis in excerpt?
- Dynamic Menu drops pages?
- Aspx/Rss feed – failed to open stream: Redirection limit reached
- Adding an Unlinked Space in a Custom Function
- page 1 is not paged
- Uses for function: wp_update_user
- WP insert post Redirect after function has executed
- Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given
- How to Send Pingbacks for all Posts in WordPress?
- How to output the taxonomies that are assigned to each custom post?
- HTML comment cause issue in functions.php script root
- Programmatically add a product to the cart and set price to zero when buying from certain category
- I want to show cart items number if any or nothing, simple CART text
- Exclude category from function – PHP
- Hide a specific category title from displaying on site
- Handling form actions in WordPress
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- Set user status to absent on WordPress
- Shortcode’s output to use as other shortcode’s parameter
- Populate Posts based on category selected using AJAX that means without page refresh
- Displaying POST content with HTML tags and all
- PHP script to redirect traffic based on website accessed
- How to remove title tag with this filter
- Why transition_post_type hook is called twice for the same post?
- Can’t get_users info by using json_encode
- Showing wordpress latest post thumbnails in slider with auto increment
- My function echos only “array”
- Notify admin (by email) if post added with specific tag
- Retrieving specific images from Media Library
- Can’t put a hyperlink on Featured Post’s Image
- Page returning ID from array, how to return the correct values for post in acf wordpress
- WordPress HTML Helper
- List sibling pages widget, exclude current page
- Permission error on plugin save
- Removing all my hardcoded URLs with get_site_url()
- Display default WordPress login/registration form into a modal window
- Highlight main menu when on specific posts or pages
- Pull GET parameter from URL in functions.php
- Adding Gravity Form With if(is_page) Is Not Working
- Send foreach $_post method to contact form 7 [closed]
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- Dynamic Email Handler with ‘header (“Location: …’
- change title of page dynamically
- Custom plugin doesn’t show in admin menu – when code added, displays an empty page