WordPress.org

Forums

[resolved] WP_Query help (3 posts)

  1. goldmember
    Member
    Posted 4 years ago #

    on this page i'm using the code below to show the 25 most recent posts from category 4.

    <?php
    $custom_query = new WP_Query( 'posts_per_page=25&cat=4' );
    if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
    
    <h3><?php the_title(); ?></h3>
    <h6><?php the_time('F j, Y') ?></h6>
    <?php the_content(); ?>
    <hr class="homenews" />
    <?php previous_posts_link('« Older Entries', 0) ?>
    <?php endwhile; else : ?>
    
    <h3>Sorry...</h3>
    <p>No posts were found.</p>
    
    <?php endif; ?>

    i thought this line of code <?php previous_posts_link('« Older Entries', 0) ?> would add a link to the bottom of the page that shows a link to previous entries but for some reason the link does not appear.

    please advise how I can get it to show. thanks in advance

  2. vtxyzzy
    Member
    Posted 4 years ago #

    I think you need to use query_posts() instead of WP_Query and add the 'paged' argument to the query.

  3. goldmember
    Member
    Posted 4 years ago #

    based on what i read in another thread where they addressed this same issue, I would think the code below would work.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    but if you look on the page where i'm testing this code, i'm getting a parse error message.

    please advise. thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic