WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Posts & Pagination (9 posts)

  1. SebAshton
    Member
    Posted 3 years ago #

    I know this subject has been done to death but having read all the other resolved posts I still seem to be at a loss as to get this up and working.

    What I want to happen is the previous_posts_link and next_posts_link functions to work within my custom page type loop but they do not. paged is set in the query.

    At a bit of a loss, so any help would be appreciated.

    Code: Here on pastebin

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    what is not working?
    do you get the '3 / 7' numbers?
    where are the next/prev links going to?

    a link to your site might help to illustrate the issue.

  3. SebAshton
    Member
    Posted 3 years ago #

    Hi alchymyth,

    The previous_posts_link/next_posts_link don't recognise that there are posts to paginate to, so they don't show up.

    Yes the page number shows up but they don't rely on the paginated data.

    Link

  4. MartinLeclercq
    Member
    Posted 3 years ago #

    I also tried to get that right. Does it have something to do with using wp_query?

  5. Digital Raindrops
    Member
    Posted 3 years ago #

    I found this post today it may be just what you are looking for?

    //The Query
    <?php $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; ?>
    // current page times the amount you want to show per page -chapeau Justin Tadlock
    <?php $offset = ( 1 * $paged ) - 1; ?>
    <?php $args=array(‘paged’=>$paged, 'posts_per_page'=>1, 'post_type'=>'issue', 'offset' => $offset); ?>
    <?php query_posts($args); ?>
    
    //The Loop
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    //what you want to display from the query… excerpt images etc..
    
    <?php endwhile;?>

    David

  6. SebAshton
    Member
    Posted 3 years ago #

    @adeptris && @MartinLeclercq

    The issue is with the use of wp_query

    replace that with query_posts and it works like a charm.

  7. MartinLeclercq
    Member
    Posted 3 years ago #

    Do you mean I have to change it in how to address the loop for the custom post type?
    How does your call for the custom post type loop then look like?

  8. SebAshton
    Member
    Posted 3 years ago #

    @MartinLeclercq my code now looks like this:

    $paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1 ;
    $args = array( 'order' => 'DESC', 'orderby' => 'date', 'paged' => $paged, 'post_type' => 'issue', 'posts_per_page' => 1 );
    
    query_posts( $args );
    
    if (have_posts()) :
    
    while ( have_posts() ) : the_post();
    ...
  9. MartinLeclercq
    Member
    Posted 3 years ago #

    ah yes, that's it. Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic