Support » Fixing WordPress » "Next" button on "get pages" page

  • Hello!

    I’m currently using this code to show all the immediate children of a certain page on the website:

    <?php $mypages = get_pages( array( 'child_of' => $post->ID, 'parent' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );
    	foreach( $mypages as $page ) {
    		$excerpt = $page->post_excerpt;
    		if ( ! $excerpt ) // Check for empty page
    		$excerpt = apply_filters( 'the_content', $excerpt );
    <br />
    <h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2>
    <div class="entry"><?php echo $excerpt; ?></div>
    <br />
    <hr />

    I’m essentially using it to create a “blog” made up of pages (all the children of the page containing this code.) Now, the question is, I want to only show 5 of the pages at a time, and have a “View More” or “View Previous” or even better, a “1 2 3 4…12” nav-type button at the bottom.

    How do I do this?


Viewing 15 replies - 1 through 15 (of 16 total)
  • Here is an article that shows how to use paginate_links() to paginate an array:

    How do I implement this? To I add it after my last line of PHP, or what?


    You can’t just add in the code, it must be merged. I think this is what you need to do, but I can’t test it, so it may not work.

    • Substitute your ‘$mypages = get_pages(…’ line for the ‘$rows = $wpdb->get_results(…’ line.
    • Change $rows to $mypages in the ”total’ => ceil(sizeof($rows)/$rows_per_page),’ line.
    • Put the code from your foreach loop inside the for loop instead of the ‘echo “I:$i ID:{$row->ID} …’ line.
    • Change the ‘$row = $rows[$i];’ line to ‘$page = $mypages[$i];’

    Ok, I went ahead and took the code from the website you linked, and then substituted my codes in the areas you described.

    My page wouldn’t even show up (error code). I went ahead and, for kicks, got rid of my code all together and just simply used the code on the site. Again, I got an error code.

    So, I’ll rephrase my question. How do I paginate an array of pages?

    The code straight from the site had an error in the SELECT statement caused by copying the code. Please try it again. I just tested it and it now works.

    The error message by itself does not help much without being able to see all the code. Please put the code in a pastebin and post a link to it here.

    Is this what you mean?

    The last few lines of your code should look like this:

    <h2><a>ID ); ?>"><?php echo $page->post_title; ?></a></h2>
    <div class="entry"><?php echo $excerpt; ?></div>
    <hr />
    <?php  } ?>

    I made the change, but I’m still getting an error on line 33, which is much further up. I think it’s the

    ‘$rows_per_page = 5;’

    line. Thoughts?

    If line 33 is ‘$rows_per_page = 5;’, then you didn’t put all your code in the pastebin. That line is line 2 in the pastebin. Please put the entire php file in the pastebin.

    Ok, here’s the full code.

    Perhaps I need to have something in my “functions” file that isn’t there?

    Something is still not adding up. The code you pasted compiles without any errors.

    Maybe your page is assigned a different template?

    Nope, correct template. Is it possible that the code is relying on some sort of code in the functions.php file that isn’t there? I made the theme I’m using from scratch. Perhaps that’s it?

    The error should be in cases-page.php, not functions.php.

    I really can’t diagnose any further without seeing the actual code that causes the error.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘"Next" button on "get pages" page’ is closed to new replies.