Forums

[resolved] [Plugin: Posts 2 Posts] Prev Next and Pagination with Post to Post (5 posts)

  1. nhankla
    Member
    Posted 3 weeks ago #

    Hello,

    I am having some issues with the Post to Post and prev and next buttons
    This is what I have for the next posts

    <div class="nav-next bx-next"><?php next_posts_link( __( 'Next →', 'boilerplate' ) ); ?></div>
    
            <div class="number"><?php current_paged(); ?></div>
    		<div class="nav-previous bx-prev"><?php previous_posts_link( __( '← Previous', 'boilerplate' ) ); ?></div>

    My connections

    function my_connection_types() {
        // Make sure the Posts 2 Posts plugin is active.
        if ( !function_exists( 'p2p_register_connection_type' ) )
            return;
    
        // Keep a reference to the connection type; we'll need it later
        global $my_connection_type;
    
        $my_connection_type = p2p_register_connection_type( array(
    		'name' => 'art_to_artists',
            'from' => 'art',
            'to' => 'artist',
    		'admin_column' => 'any',
    		'reciprocal' => true
        ) );
    }
    add_action( 'wp_loaded', 'my_connection_types' );

    My page that is pulling the artist information

    <?php  $artist = $post; ?>
    
      <?php
    			global $my_connection_type;
    
    					// Find connected pages
    					$connected = $my_connection_type->get_connected( get_queried_object_id() );
    
    			// Display connected pages
    				if ( $connected->have_posts() ) :
    
    				?>
      <?php while ( $connected->have_posts() ) : $connected->the_post(); ?>

    What I want to do is have a prev and next on top of each art piece and have it go to the next piece under that artist. Currently it is not doing that at all. Not showing up.

    Thanks

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. scribu
    Member
    Posted 3 weeks ago #

    That's because next_posts_link() checks the $wp_query variable, instead of $connected.

    Two options:

    1) use query_posts()
    2) use the WP PageNavi plugin

  3. nhankla
    Member
    Posted 3 weeks ago #

    HI Scribu,
    Thanks for the reply.
    I actually fixed it by changing the wp_query

    $paged = ( get_query_var( 'paged' ) ) ? get_query_var('paged') : 1;
     $wp_query = new WP_Query( array(
      'connected_type' => 'art_to_artists',
      'connected_items' => get_queried_object_id(),
       'paged' => $paged
    
    ) );
    
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

    And adding in the max num pages fix for the links

    $total_pages = $wp_query->max_num_pages;
    <div class="nav-next bx-next"><?php next_posts_link( __( 'Next →', $total_pages ) ); ?></div>
    <div class="nav-previous bx-prev"><?php previous_posts_link( __( '← Previous', $total_pages ) ); ?></div>

    Thanks Again!

  4. scribu
    Member
    Posted 3 weeks ago #

    You're passing $total_pages to __(), instead of to next_posts_link(), which has no effect.

  5. nhankla
    Member
    Posted 3 weeks ago #

    Thanks Scribu,

    <?php if (  $wp_query->max_num_pages > 1 ) : 
    
     $current_page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
    	$total_pages = $wp_query->max_num_pages;
    
      ?>
    
      <div id="nav-above">
    <div class="nav-next bx-next"><?php next_posts_link('Next &rarr;', $total_pages ); ?></div>
    
            <div class="number"><?php echo $current_page.' / '.$total_pages ; ?></div>
    		<div class="nav-previous bx-prev"><?php previous_posts_link( '&larr; Previous', $total_pages  ); ?></div>
            </div>

    This is cleaned up and works great.

Reply

You must log in to post.

About this Topic