Hi,
Do you think it's possible to create an url rewriting for the pagination of a view ?
I want to be sure that Google see all results and the website has a proper seo... by example :
hidden link
hidden link
etc.
instead of &wpv_column_sort_id=post_date&wpv_column_sort_dir=desc&wpv_view_count=1&wpv_paged=1
Thank you in advance for your answer,
Regards
Dear Emmanuel,
One way to do this is by using the WP-PageNavi plugin. You need to add the following code to functions.php in your theme:
// Get the page number into wp_pagenavi
function pagenavi_paged($q) {
$types = (array)$q->get('post_type');
if (in_array('test', $types)) {
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$q->set('paged', $paged);
}
}
add_action('pre_get_posts', 'pagenavi_paged');
// Replace wpv-pagination shortcode
function wpv_pagenavi($args, $content) {
global $WP_Views;
wp_pagenavi( array('query' => $WP_Views->post_query) );
}
add_shortcode('wpv-pagination', 'wpv_pagenavi');
Remember to replace 'test' with your custom post type.
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Caridad
Hi,
Thank your for your precious answer 🙂
I don't use a custom post type... but if I delete the condition " if (in_array('test', $types)) {" it's work well for all my views with pagination (very good).
But now, maybe you could help me to add a last condition. The problem is I use somes Views with Ajax, and other Views with a static and manuel pagination.
I see with this script that when I want to use Ajax, this script make that Ajax don't work...
Maybe in your script you could add the possibility to load him for certain Views or add a condition to load him only if a views don't use Ajax.
It will be very perfect if we can do it 🙂
Best regards,
Emmanuel
Dear Emmanuel,
We need to change the code a little bit, like this:
// Get the page number into wp_pagenavi
function pagenavi_paged($q) {
if (get_query_var('paged')) {
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$q->set('paged', $paged);
}
}
add_action('pre_get_posts', 'pagenavi_paged');
// Add a custom wp_pagenavi shortcode
function wpv_pagenavi($args, $content) {
global $WP_Views;
wp_pagenavi( array('query' => $WP_Views->post_query) );
}
add_shortcode('wpv-pagenavi', 'wpv_pagenavi');
Instead of overwriting the wpv-pagination shortcode, we are creating a new one: wpv-pagenavi. This way you can use the original shortcode in your ajax pagination and replace the shortcode in your normal pagination to [wpv-pagenavi]
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Caridad
Hi,
Woow 🙂 I love you CaridadZ 😀
It's work perfectly !
I think this is a good solution, it's a professionnal result, maybe it's could help someone else.
I'm happy and appreciate your support. Thank you !
Regards,
Emmanuel
This was helpful for me too, thanks!
Anyway I have the pagination shown in top of the view even it is set below the loop.
Any idea what is happening here?