How to change URL structure for pagination pages?

Hi I'm new to WordPress hence if my question was simple or stupid I'm sorry, but please someone tell me how to change URL for pagination pages. Currently I'm having URL for pagination pages as: www.example.com/category_name.html/1 www.example.com/category_name.html/2 www.example.com/category_name.html/3 etc. But I need to change this URL structure as: www.example.com/category_name.html?page=1 www.example.com/category_name.html?page=2 www.example.com/category_name.html?page=3 etc. I tried something like this but it's not working. add_action( 'init', 'add_author_rules' ); function add_author_rules() { add_rewrite_rule( "bycategory/108-abodes-of-vishnu)/?$", "category_name=$matches[1]&paged=$matches[2]", "top"); } Any help would be greatly appreciated.
Category: Web

Custom post type archive page pagination

I have set up an archive page for my custom post type reference, where I use a query to get all posts of type reference. This works, but when I try to paginate the result, it doesn't work. Right now, it doesn't even print out the pagination links. EDIT: This was earlier used on a regular page, but I changed it to an archive page. That's when the pagination broke. Here is the source code; Custom post type reference (plugin) …
Category: Web

Paginate Links in Wp Query Shortcode

so been looking around for this answer, but no go -- basically i have a WP Query that is incased in a shortcode.. I have set up the paginate links function which outputs it on the page. However, the page url does not change when clicked (href does show the correct url -- /page/2) I know it is something with the main Query when executed in a shortcode. Any help would be greatly appreciated. $paged = ( get_query_var( 'paged' ) …
Category: Web

Pagination not working on custom post types with rewrite slug

I've been trying to fix my pagination to work on custom post type slugs for example article/post-title/page/2 it just keeps showing the first page's results, the URL is changing but the posts remain the same My post type has rewrite slugs written like this 'rewrite' => ['slug' => 'article'], This is the query I used $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $args = [ 'numberposts' => -1, 'post_type' => $post_type, 'posts_per_page' => $post_per_page, 'post_status' => 'publish', 'paged' …
Category: Web

How to Show Next-Previous Link Only

I can not figure out how to keep Next and Previous links only and remove page number links. I also tried using this: previous_post_link(); next_post_link(); But it's not working. While using the following page templates to display all comments on the website: <?php /* Template Name: Display All Comments Template Post Type: page Author: www.theidioms.com */ ?> <?php get_header(); ?> <div class="blocks main-block"> <div class="article"> <h1 id="title" class="page-heading"><?php the_title(); ?></h1> <?php /*Set how many comments per page*/ $comments_per_page=4; /*Count comments …
Category: Web

paginate_links and query vars

I have using the Wordpress paginate_links() to build a paginator on a custom archive template for a custom post type. My site uses permalinks: <?php echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'current' => max(1, get_query_var('paged')), 'format' => 'page/%#%', 'total' => $wp_query->max_num_pages, )); ?> This works fine until I try to add query string vars to build a custom search string when the paginator echoes: .../entries?post_type=entry&s=testpage/1 .../entries?post_type=entry&s=testpage/2 Instead of: .../entries/page/1?post_type=entry&s=test .../entries/page/2?post_type=entry&s=test and so on... How can I get the correctly …
Category: Web

get_next_posts_link not working without parameter max_num_pages

I have a custom search page (searchpage.php) using pagination, and I am tring to add lines like below dynamically to my header.php inside <head></head> tag for better pagination SEO. <link rel="prev" href="https://www.example.com/search/cats/page/2/"> <link rel="next" href="https://www.example.com/search/cats/page/4/"> While doing this, I have used below code mentioned here in functions.php. <?php function rel_next_prev(){ global $paged; if ( get_previous_posts_link() ) { ?> <link rel="prev" href="<?php echo get_pagenum_link( $paged - 1 ); ?>" /><?php } if ( get_next_posts_link() ) { ?> <link rel="next" href="<?php echo …
Category: Web

Pagination is not working on custom query inside a custom home page template

I know this is a duplicate question. But to comment on existing question, I dont have enough points. So here we go.... Pagination is not working on custom query inside a custom home page template. The solution (which worked for many others) below is taken from another question. How to fix pagination for custom loops? <div class="most-popular type-1"> <h3 class="section-headline"><?php _e('Most Popular','themename'); ?></h3> <div class="widget-articles clearfix"> <?php $mostpopular_args=array( 'post_type' => 'post', 'orderby' => 'meta_value_num', 'meta_key' => 'view_count', 'posts_per_page' => '10', …
Category: Web

Help to modify wp_link_pages()

My site has the Newspaper theme by tagDiv, which installs two necessary plugins to make things work better. These plugins are Composer and Standard Pack. I'm trying to modify the default wp_link_pages() but I don't know how because one of these plugins has code that changes the function. I don't want to change the plugin file because it is frequently updated. The problem is that the code is not inside a post file like single.php. And I'm not finding a …
Category: Web

Archive page for Wordpress Custom Post Type doesn't show pagination from paginate_links()

I have a custom post type with courses-events as the slug. In functions.php, I have: add_action( 'pre_get_posts', 'custom_archive_items' ); function custom_archive_items( $query ) { if ($query->is_main_query() && !is_admin() && is_post_type_archive( 'courses-events')) { $query->set( 'posts_per_page', '1' ); } } I know the above is firing for my archive page if I dump $query in the condition, it is visible. On archive-courses-events.php I have simply: if ( have_posts() ) : while(have_posts()) : the_post(); <!-- my output --> endwhile; echo paginate_links(); endif; I …
Category: Web

Last page in pagination does not match max_num_pages - the overall post count is less according to pagination

I'm using paginate_links() to display my posts pagination like this: $paged = get_query_var('paged'); $current_page = max(1, $paged); $custom_query = array( 'post_status' => 'publish', 'posts_per_page' => 4, 'paged' => $current_page ); $query = new WP_Query($custom_query); if($query->have_posts()) { // The pagination comes after displaying the posts: echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'format' => 'page/%#%', 'current' => $paged, 'total' => $query->max_num_pages, 'prev_text' => 'Prev', 'next_text' => 'Next' )); } To be specific with numbers, there are 571 posts on the website. …
Category: Web

Combining WordPress pagination functions for archives and search results

I am currently modernising an old WordPress theme (a standalone theme, not a child of any official themes). Trying to build pagination I am finding some issues creating one function that works for both archives and search. The first snippet works fine with archives (categories, loops, etc): function pagination_bar() { global $wp_query; $total_pages = $wp_query->max_num_pages; if ($total_pages > 1){ $current_page = max(1, get_query_var('paged')); echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'format' => 'page/%#%', 'current' => $current_page, 'total' => $total_pages, 'prev_text' …
Category: Web

search with pagination not working as expected

Why is this url pattern taking me to a 404 page where i saw in some other sites this same pattern works fine with search and paginate please help me i am new to wordpress and don't know why this is happening anyone who is experienced can tell me whats wrong here looking for helpful answers , thanks in advance $search = get_query_var("s"); $page_num = get_page_num(); $query = new WP_Query(array( "posts_per_page" => 4, "paged" => $page_num, "post_type" => "post", "s" …
Category: Web

Pagination contents not changing in Front page WordPress

This question has asked many time before and none has answers my question. I went through most of the answers before post this. I have a pagination query in home page. Pagination is showing and I can going through the pages. But same posts are displaying for every paginate link. This is my code so far. Can anybody elaborate the wrong here? <?php $paged = ( get_query_var('page') ) ? get_query_var('page') : 1; $args = array( 'post_type'=>'post', 'posts_per_page'=>10, 'orderby'=>'date', 'order'=>'DESC', 'offset'=>3, …
Category: Web

Add css class to Pagination?

I've been using this code: $current_page = get_query_var('paged'); $current_page = max( 1, $current_page ); $per_page = 12; $offset_start = 1; $offset = ( $current_page - 1 ) * $per_page + $offset_start; $post_list = new WP_Query(array( 'cat' => -15, 'posts_per_page' => $per_page, 'paged' => $current_page, 'offset' => $offset, // Starts with the second most recent post. 'orderby' => 'date', // Makes sure the posts are sorted by date. 'order' => 'DESC', // And that the most recent ones come first. )); …
Category: Web

How to change custom paginated URLs using PHP code

See our website has pagination URls like below https://www.xxxxxxxx.com/xxxxxxxx/yyyy/zzz/?xx_xxx_page=2 https://www.xxxxxxxx.com/xxxxxxxx/yyyy/zzz/?xx_xxx_page=3 https://www.xxxxxxxx.com/xxxxxxxx/yyyy/zzz/?xx_xxx_page=4 ISSUE: These pagination URLs are not indexing by Google. (As it has showing same canonical URL for all these pagination URLS , it showing error as Duplicate URL) Proposed solution: we want to create all these pagination pages separately with Specific permalink(URL). Without changing URL Structure and without disturbing Pagination https://www.xxxxxxxx.com/xxxxxx/yyyy/zzz-2/ https://www.xxxxxxxx.com/xxxxxx/yyyy/zzz-3/ Any one please help me with fasible solutions. Thank you
Category: Web

How to add pagination in Terms

Hello on my website I have created a page where it will show all of the Woo Commerce tags in the store in list format. The problem here is that I am unable to paginate them. I have tried paginate_links function too but that's not working. Here is my shortcode which I created function showalltags(){ $terms = get_terms( array( 'hide_empty' => true, 'taxonomy' => 'product_tag', ) ); $html = '<ul class="post_tags">'; if($terms){ foreach($terms as $term){ $term_link = get_term_link( $term->term_id, 'product_tag' …
Category: Web

Pagination not working - FrontPage

I'm trying to add pagination through function.php. No Output! What I'm missing? function simpleblog() { $query = 'posts_per_page=6'; $queryObject = new WP_Query($query); // The Loop... if ($queryObject->have_posts()) { while ($queryObject->have_posts()) { $queryObject->the_post(); //the_title(); //the_content(); get_template_part( 'content' ); echo '<hr class="empty-space-hr">'; } } else { //no post found } echo'<div class="pagination">'; echo paginate_links( array( 'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ), 'total' => $query->max_num_pages, 'current' => max( 1, get_query_var( 'paged' ) ), 'format' => '?paged=%#%', 'show_all' => …
Category: Web

Paged posts - how to use numbers and next/previous links?

I want wp_link_pages (mutli-page posts) to display the page numbers, the word "previous" before those numbers, and a "next" after those numbers. It would look like this: Prev 1, 2, 3, 4 Next I'm attempting to do this without a plugin. Here's what I've tried so far, but it isn't working, it is only displaying numbers. <?php wp_link_pages(array( 'before' => '<span style="clear:both; display:block">Pages', 'after' => '</span>', 'next_or_number'=>'number', 'previouspagelink' => 'previous', 'nextpagelink'=> 'Next' )); ?>
Category: Web

Paginate_links won't create the right links on a taxonomy filtered custom post type archive

after hours and dozen of tests and messes... i'm face to the wall and fed up searching (mainly cuz my google's answers are already all clicked !) I'm trying to display paginate_link with a filters taxonomy form (AGAIN ????? ;). With all solutions here, I've found how to get the right numbered pagination in a result of my form only on the first page of the results. The main problem, is in the pagination links, they are using the wrong …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.