WordPress.org

Ready to get started?Download WordPress

Forums

Smarter Navigation
[resolved] Smarter navigation with previous/next thumbnails (9 posts)

  1. bostonreal
    Member
    Posted 1 year ago #

    Here is my current thumbnail navigation code:

    <div id="post-nav">
        <?php $prevPost = get_previous_post(true);
            if($prevPost) {
                $args = array(
                    'posts_per_page' => 1,
                    'include' => $prevPost->ID
                );
                $prevPost = get_posts($args);
                foreach ($prevPost as $post) {
                    setup_postdata($post);
        ?>
            <div class="post-previous">
                <a>">«Previous Post</a>
                <a>"><?php the_post_thumbnail('thumbnail'); ?></a>
                <h4><a>"><?php the_title(); ?></a>
            </div>
    
        <?php
                    wp_reset_postdata();
                } //end foreach
            } // end if  
    
            $nextPost = get_next_post(true);
            if($nextPost) {
                $args = array(
                    'posts_per_page' => 1,
                    'include' => $nextPost->ID
                );
                $nextPost = get_posts($args);
                foreach ($nextPost as $post) {
                    setup_postdata($post);
        ?>
            <div class="post-next">
                <a>">Next Post»</a>
                <a>"><?php the_post_thumbnail('thumbnail'); ?></a>
                <h4><a>"><?php the_title(); ?></a>
            </div>
        <?php
                    wp_reset_postdata();
                } //end foreach
            } // end if
        ?>
    </div>

    Any help here would be greatly appreciated. Thank you!

    http://wordpress.org/extend/plugins/smarter-navigation/

  2. versusbassz
    Member
    Plugin Author

    Posted 1 year ago #

    $prev_post_id = get_adjacent_id_smart( true );
    	if( $prev_post_id ) {
    		$args = array(
    			'posts_per_page' => 1,
    			'include' => $prev_post_id
    		);
    		$prevPost = get_posts( $args );
    		foreach ( $prevPost as $post ) {
    			setup_postdata( $post );
    			?>
    			<div class="post-previous">
    
    				<a href="<?php the_permalink(); ?>">«Previous Post</a>
    
    				<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
    
    				<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
    
    			</div>
    
    			<?php
    			wp_reset_postdata();
    		} //end foreach
    	} // end if

    Please, try this for previous post block, and same for next post block with "get_adjacent_id_smart()" at first line.

    So, get_adjacent_id_smart() - returns next post id,
    get_adjacent_id_smart( true ) - returns previous post id
    of course smarter functionality works with it =)

  3. bostonreal
    Member
    Posted 1 year ago #

    thank you versusbassz for the speedy response! works perfectly!!!

  4. bostonreal
    Member
    Posted 1 year ago #

    After running a few tests on different browsers I noticed that the smarter navigation thumbnails were not appearing on every post.

    When I log in, however, works flawlessly. Any idea as to what could be causing this behavior?

    Thank you!

  5. bostonreal
    Member
    Posted 1 year ago #

    Turns out WP Super Cache was the culprit. Sorry to bother you again, Smarter Navigation works perfectly now, thank you!

  6. gusevstudio
    Member
    Posted 12 months ago #

    versusbassz Please, post code for previous and next posts blocks with thumbs.

    Thanks!

  7. jdhub
    Member
    Posted 8 months ago #

    I'm trying to do the same thing here and I wasn't having any luck.

    I tried stripping this down to the essentials, and I discovered that when I simply echo get_adjacent_id_smart(true) or get_adjacent_id_smart(false), I get -1. See example:

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
        	<p><?php previous_post_smart();?> | <?php next_post_smart();?></p>
    		<?php $prev_post_id = get_adjacent_id_smart( true ); echo $prev_post_id; endwhile; ?>

    Using the default previous/next_post_smart links works just fine.

    I'm using this on a custom post type.

    Any help is greatly appreciated!

  8. jdhub
    Member
    Posted 8 months ago #

    Also, I'm running 3.7.1

  9. esmi
    Forum Moderator
    Posted 8 months ago #

    @jdhub: As per the Forum Welcome, please post your own topic.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic