WordPress.org

Ready to get started?Download WordPress

Forums

"Next" button on "get pages" page (17 posts)

  1. manythingsme
    Member
    Posted 2 years ago #

    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
    			continue;
    		$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 />
    	<?php
    	}
    ?>

    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?

    Thanks!
    John-Andrew

  2. vtxyzzy
    Member
    Posted 2 years ago #

    Here is an article that shows how to use paginate_links() to paginate an array:

    http://wordpress.mcdspot.com/2010/11/25/pagination-using-paginate_links/

  3. manythingsme
    Member
    Posted 2 years ago #

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

    Thanks!

  4. vtxyzzy
    Member
    Posted 2 years ago #

    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];'
  5. manythingsme
    Member
    Posted 2 years ago #

    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?

  6. vtxyzzy
    Member
    Posted 2 years ago #

    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.

  7. manythingsme
    Member
    Posted 2 years ago #

  8. vtxyzzy
    Member
    Posted 2 years ago #

    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.

  9. manythingsme
    Member
    Posted 2 years ago #

    Is this what you mean?

    http://pastebin.com/DM6sbJpu

  10. vtxyzzy
    Member
    Posted 2 years ago #

    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
    	}
    	?>
    
    <?php  } ?>
  11. manythingsme
    Member
    Posted 2 years ago #

    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?

  12. vtxyzzy
    Member
    Posted 2 years ago #

    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.

  13. manythingsme
    Member
    Posted 2 years ago #

    Ok, here's the full code.

    http://pastebin.com/YReFJDER

    Perhaps I need to have something in my "functions" file that isn't there?

  14. vtxyzzy
    Member
    Posted 2 years ago #

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

    Maybe your page is assigned a different template?

  15. manythingsme
    Member
    Posted 2 years ago #

    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?

  16. vtxyzzy
    Member
    Posted 2 years ago #

    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.

  17. manythingsme
    Member
    Posted 2 years ago #

    Ok, I think I'm going to use the code I have, and then use a jquery pagination...I wish the PHP had worked out. :/

Topic Closed

This topic has been closed to new replies.

About this Topic