0

I don't have any code or pages to show yet so I'll just have to describe my question.

I have group of posts, no categories or taxnomoy yet.

On my home page I have a 'View all posts' link that is linked to a view_all_post.php page.

On the view_all_posts.php page I have a simple loop that shows all the posts.

I only want to show 10 posts on the view_all_posts.php page and have the rest of the posts on the next page that will be linked on the view_all_posts page.

So the view_all_posts will show 10 post and then have links to show the next page with the rest of the links on, that will have links to the next page if there are more posts to show.

I know how to limit the number of post - post_per_page

My problem is how to create the extra pages with the rest of the posts.

I'm sure I don't create another view_all_post page because I don't know how many post there will be and so it won't be dynamic.

Is there a template page I should be using like single.php to show actual posts.

If it helps here is the view-all-post.php

<h2>View all Posts</h2>


<section class="allPosts”>

    <?php
        $allposts_args  = array(
            'post_type' => 'post',
            'order' => 'ASC',
            'orderby' => 'date',
            'posts_per_page' => 10,
        );

        $allposts_loop = new WP_Query($allposts_args);

        if($allposts_loop->have_posts()):
            while($allposts_loop->have_posts()):
                $allposts_loop->the_post();

    ?>

    <div class=“thePost">

        <a href="<?php echo get_permalink($post->ID); ?>">  
            <h3><?php echo the_title(); ?></h3>
            <h4>by </h4>

            <p><?php echo the_content(); ?></p> 
        </a>
    </div>  

    <?php
        endif;
        endwhile;
    ?>

    <?php wp_reset_postdata(); ?>

</section>  
4
  • Please edit your question and post the code from view_all_posts.php. Without that is is impossible to help you Commented Jun 23, 2014 at 7:23
  • Hi - I have updated with the page code
    – user51442
    Commented Jun 23, 2014 at 7:44
  • You got 10 post using this code? Commented Jun 23, 2014 at 7:53
  • Yes, I want to show 10 post on the first page and the rest on the next page and so on.
    – user51442
    Commented Jun 23, 2014 at 7:59

1 Answer 1

0

You have not made provision for pagination, which is integral for what you want to do. You should go and have a look at how to construct a custom query and how to make use of the pagination parameters in WP_Query

You will also need to go and have a look at next_posts_link and previous_posts_link which is used to navigate your pages to the next/previous set of posts. This is very simple navigation links. There are more sophisticated pagination functions out there, it is just a matter of searching with google.

It is important that you know and understand how the next_posts_link is used in custom queries work, otherwise your pagination won't work at all

Something like this will do the trick. But you need to go and read the links I've provided so that you understand what I've had done

<?php
// set the "paged" parameter (use 'page' if the query is on a static front page)
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

$allposts_args  = array(
            'post_type' => 'post',
            'order' => 'ASC',
            'orderby' => 'date',
            'posts_per_page' => 10,
            'paged' => $paged
        );

        $allposts_loop = new WP_Query($allposts_args);

        if($allposts_loop->have_posts()):
            while($allposts_loop->have_posts()):
                $allposts_loop->the_post();

    ?>

<---YOUR LOOP--->

           endwhile;

       // next_posts_link() usage with max_num_pages
       next_posts_link( 'Older Entries', $allposts_loop->max_num_pages );
       previous_posts_link( 'Newer Entries' );

wp_reset_postdata(); 

endif;

You should also have a look at Debugging Wordpress when you are developing a theme. You should first end your while statement before you end your if statement, not the other way around. And wp_reset_postdata(); should be called before your endif statement

1
  • Did my answer solved your problem. If yes, please consider accepting my answer by clicking on the check mark on the left of my answer below the up/down arrow. If not, what problem do you still have? Commented Jul 6, 2014 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.