Support » Plugin: Smarter Navigation » [Plugin: Smarter Navigation] Using next_post_smart() for complex next/previous links

  • Resolved Parakoos

    (@parakoos)


    Sometimes, a simple textual link to the next/previous links doesn’t cut it. I, for example, bring back the post IDs of the next/previous posts and construct nice links using the post thumbnail.

    You can do this with Smart Navigation using a, for reasons unknown, undocumented method called get_adjacent_id_smart(). Here is an example from my single.php:

    $tmn_next_post = get_post(get_adjacent_id_smart( false ));
    $tmn_previous_post = get_post(get_adjacent_id_smart( true ));

    You can see a working example of this on The Modern Nomad.

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Actually, there is an added complication with the above. For some reason, if there is no next or previous post, the get_adjacent_id_smart() method returns the current post! So to fix this, you need something like this:

    $tmn_next_post = get_post(get_adjacent_id_smart( false ));
    $tmn_previous_post = get_post(get_adjacent_id_smart( true ));
    if( $tmn_next_post->ID == get_the_ID() ) { $tmn_next_post = false; }
    if( $tmn_previous_post->ID == get_the_ID() ) { $tmn_previous_post = false; }
    Plugin Author scribu

    (@scribu)

    if there is no next or previous post, the get_adjacent_id_smart() method returns the current post!

    That is not accurate. When there’s no post, get_adjacent_id_smart() returns false. But, when you pass false to get_post(), it returns the current post.

    Either way, thanks for taking the time to share your knowledge of the plugin.

    Ahhh. Got it. My bad.

    And thanks for an awesome plugin!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Smarter Navigation] Using next_post_smart() for complex next/previous links’ is closed to new replies.