- This topic has 9 replies, 2 voices, and was last updated 5 years, 9 months ago by Tom.
-
AuthorPosts
-
June 21, 2018 at 3:44 am #605046Alberto
Hello
I’m working with a chil theme so I use a home.php where I modify the loop with this code:$args = array( 'post_type' => 'post', 'category_name'=> 'blog-marketing', 'posts_per_page' => 10, 'paged' => get_query_var( 'paged' ) ); $lazo = new WP_Query( $args ); if ( $lazo->have_posts() ) : while ( $lazo->have_posts() ) : $lazo->the_post(); get_template_part( 'content', get_post_format() ); endwhile; generate_content_nav( 'nav-below' ); else : get_template_part( 'no-results', 'archive' ); endif;
The problem is the navigation between pages, cause it counts all the posts.
I need it to works only with the posts filtered in my query.
How can I achieve that?Thanks.
June 21, 2018 at 8:54 am #605376TomLead DeveloperLead DeveloperHi there,
Just so I understand – the pagination is counting every single post, not just the posts in your specified category?
June 21, 2018 at 9:57 am #605446AlbertoHello Tom!
Exactly!
You can see it in traduccioneschino.es/blog
It must only show 10 pages instead 17.Regards
June 21, 2018 at 9:16 pm #605737TomLead DeveloperLead DeveloperAre you sure your template is working? If you add some random code (
echo 'hi';
), do you see it on the page?June 22, 2018 at 1:24 am #605830AlbertoHi Tom!
I suppose you’re talking about home.php… and the answer is yes, of course, in fact the first paragraph you see (“Sección publicada por especialistas…”) has been writed in a div into that file.June 22, 2018 at 9:09 am #606186TomLead DeveloperLead DeveloperInstead of this:
$args = array( 'post_type' => 'post', 'category_name'=> 'blog-marketing', 'posts_per_page' => 10, 'paged' => get_query_var( 'paged' ) );
Try this:
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args = array( 'post_type' => 'post', 'category_name'=> 'blog-marketing', 'posts_per_page' => 10, 'paged' => $paged );
Then after:
generate_content_nav( 'nav-below' );
Add this:
wp_reset_postdata();
Let me know 🙂
June 22, 2018 at 10:48 am #606266AlbertoHi Tom!
Not working yet. This is what I’ve got now in my home.php file$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args = array( 'post_type' => 'post', 'category_name'=> 'blog-marketing', 'posts_per_page' => 10, 'paged' => $paged ); $lazo = new WP_Query( $args ); echo '<div class="intro-blog">Sección publicada por especialistas en <strong>marketing digital</strong> y las <strong>redes sociales en China</strong>, tratando temas diversos desde herramientas de análisis, últimas noticias relacionadas con redes sociales y artÃculos relacionados con la traducción o interpretación, además se publicarán las últimas novedades de la empresa<strong> Traducciones Chino.</strong></div>'; if ( $lazo->have_posts() ) : while ( $lazo->have_posts() ) : $lazo->the_post(); get_template_part( 'content', get_post_format() ); endwhile; generate_content_nav( 'nav-below' ); wp_reset_postdata(); else : get_template_part( 'no-results', 'archive' ); endif;
And as you can check in the blog, it still shows 17 pages (nothing after page 6).
June 22, 2018 at 8:04 pm #606475TomLead DeveloperLead DeveloperAnd what happens if you replace:
generate_content_nav( 'nav-below' );
With:
the_posts_pagination();
June 25, 2018 at 1:14 am #607827AlbertoIt works the same way.
June 25, 2018 at 9:14 am #608199TomLead DeveloperLead DeveloperSo strange, I would post your code (with
the_posts_pagination()
) on https://wordpress.stackexchange.com/.Someone there might be able to spot the issue.
Let me know if they’re not able to help 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.