Pancake_Effect
asked on
Wordpress WP_Query with pagnation
Hey everyone.
So I'm desperately trying to learn/understand the code when using a loop in wordpress. I used to use query_posts instead of WP_Query which I now understand is bad practice. I've read through the wordpress codex several times and I think I have a good understanding of the loop now but I'm trying to understand how to use the rest.
So as of now this is my loop
The problems I'm running into is:
A. the previous and next posts button isn't showing (and yes I have more than two posts ;) )
B. if you go to mysite.com/page/2/ it still shows the latest two posts.
I think I need to add in some sort of $paged but I'm not sure where to implement it.
So I'm desperately trying to learn/understand the code when using a loop in wordpress. I used to use query_posts instead of WP_Query which I now understand is bad practice. I've read through the wordpress codex several times and I think I have a good understanding of the loop now but I'm trying to understand how to use the rest.
So as of now this is my loop
<?php
$args = array(
'post_type' => 'post',
'order' => 'DSC',
'posts_per_page' => '2',
);
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h1><?php the_title() ;?></h1>
<?php the_content() ;?>
<?php endwhile; else: ?>
<p>Sorry, there are no posts to display</p>
<?php endif; ?>
<?php previous_posts_link() ;?><?php next_posts_link() ;?>
The problems I'm running into is:
A. the previous and next posts button isn't showing (and yes I have more than two posts ;) )
B. if you go to mysite.com/page/2/ it still shows the latest two posts.
I think I need to add in some sort of $paged but I'm not sure where to implement it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.