• I’m loading WordPress categories into an external PHP page. Yes, it would be easy to run it all inside WordPress, but in this case that is not an option.

    I am loading 4 posts at a time. I need to include pagination links at the bottom to load the next 4 posts into the same PHP page.

    Here is what I have:

    <?php
    // Include WordPress
    define('WP_USE_THEMES', false);
    require('./articles/wp-load.php');
    query_posts('cat=9', 'posts_per_page=4');
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="https://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    
    <?php while (have_posts()): the_post(); ?>
    
    <?php endwhile; ?>
    
    <?php while (have_posts()): the_post(); ?>
    <h3><?php the_title(); ?></h3>
    <p><?php twentyten_posted_on(); ?> <?php the_excerpt(); ?></p>
    <hr />
    
    <?php endwhile; ?>
    
    </body>
    </html>
Viewing 5 replies - 1 through 5 (of 5 total)
  • can I ask what are you using a external php ? because it may be a better solution to your problem.

    Thread Starter razn8

    (@razn8)

    Just a static PHP page. I’m including the posts into the static page via the wp-load.php, and it works well as is. But I need to add the ‘next’ and ‘previous’ pagination links to the bottom of the page to load the next 4 posts from that category into the current static php page.

    For example:

    <?php next_posts_link( __( 'Older posts', 'twentyten' ) ); ?>
    <?php previous_posts_link( __( 'Newer posts', 'twentyten' ) ); ?>

    This adds the pagination links within the WP environment, but in an external environment I obviously need a custom query, for which I have had no luck with so far.

    Ok why are you using a external php file? when you can use a template file to modify your content display without using wp-load.php. and still have the next/previous functionality.

    if you don’t want/can’t do it this way than I think that you have to write your own mysql query to get this accomplish using $wpdb. here is a link that can help you

    https://codex.www.ads-software.com/Function_Reference/wpdb_Class or
    https://codex.www.ads-software.com/Function_Reference/WP_Query

    I have no idea if its the case on external php files…I do import WP to external php myself, but I’ve never tried pagination

    However, to use pagination on a custom page template displaying posts, you have to page the query

    Could be true on external php files too

    https://www.ads-software.com/support/topic/previous-custom-post-types?replies=17

    check out that thread for a discussion on pagination with query_posts

    Thread Starter razn8

    (@razn8)

    Hax: Thank you for your post. So you are saying that I can run a template file outside of the WordPress environment? If so, please direct me to some examples of how to accomplish this.

    Rev. Voodoo: Thanks for the link, I will check it out.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pagination on external php page’ is closed to new replies.