• I’m trying to return the URL only without the link e.g. <a href""></a>

    I only want to return the URL of the next or previous post. I’m using this plugin in a photoblog and intend to make the main image the prev/next link instead of having text has the link. I’ve tinkered around with various ways of acheiving this like using this:

    <?php previous_post_smart( '%link' , the_post_thumbnail( 'photoblog'));

    playing with this has resulted in lots of syntax errors or the image being displayed but without a link. I assumed grabbing only the URL would make this task easier.

    Any ideas?

    Thanks!

    https://www.ads-software.com/plugins/smarter-navigation/

Viewing 8 replies - 1 through 8 (of 8 total)
  • jefffassnacht

    (@jefffassnacht)

    @davedillonphoto,

    I got the URLs using this code:

    <?php $prev_id = get_adjacent_id_smart(true); ?>
      <a href="<?php echo get_permalink( $prev_id ); ?>"><img></a>
    
    <?php $next_id = get_adjacent_id_smart(); ?>
    <a href="<?php echo get_permalink( $next_id ); ?>"><img></a>

    There are some template tags located in smarter-navigation/template-tags.php. The template tag used above is set to false by default. So leave it blank to get next post id, and pass true to get previous post id. Of course, replace <img> with whatever you want.

    Thread Starter davedillonphoto

    (@davedillonphoto)

    Awesome, thanks!

    Thread Starter davedillonphoto

    (@davedillonphoto)

    This actually isn’t working using the following code… any ideas? I’m trying to make the “Featured image” of the post link to the previous post.

    <?php $prev_id = get_adjacent_id_smart(true); ?>
      <a href="<?php echo get_permalink( $prev_id ); ?>">
    <?php the_post_thumbnail( 'photoblog', array('alt' => ''.get_the_title().'', 'title' => ''.get_the_title().'' )); ?>
    </a>
    Thread Starter davedillonphoto

    (@davedillonphoto)

    It appears that get_adjacent_id_smart is broken for me. when I try to echo the results I always receive “-1” and no post Id. Any suggestions?

    jefffassnacht

    (@jefffassnacht)

    In this support thread the plugin author says “When there’s no post, get_adjacent_id_smart() returns false. Does get_adjacent_id_smart return a result when you don’t pass true? If it does, then the -1 means you’re at the top of the list and Smarter Navigation doesn’t loop around and grab the last post.

    Thread Starter davedillonphoto

    (@davedillonphoto)

    Thanks for the info. however it seems mine always returns -1 dispite other posts being before it. This happens when passing “False” when passing “true” i get nothing?

    Thread Starter davedillonphoto

    (@davedillonphoto)

    As an update to this…

    It appears that I receive a “-1” whenever when someone is direct linked to a post. which means “get_adjacent_ID” does not have a fallback like previous_link ?? If I go to a category page or archive page to get to a post I receive the previous ID.

    problem is, my home page is set up to direct link to the latest post… which means theres no previous ID. Is there a way to set “get_adjacent_ID” to fallback?

    you can see my site here:
    https://www.davedillonphoto.com/

    Thread Starter davedillonphoto

    (@davedillonphoto)

    I’ve created a custom function to check to see if there’s “no data” from smarter navigations “get_adjacent_ID” function. If it returns -1 i have it fall back to the native wordpress navigation. seems to work well for what I’m doing. I hope this can help someone else.

    //
    //Photoblog click thru image function
    //
    
    function previous_post_image() {
    
    echo "<a href='";	
    
          $prev_id = get_adjacent_id_smart(true);
          $prev_id_fallback = get_previous_post();
              if ($prev_id == -1) {
          echo get_permalink( $prev_id_fallback );
            } else {
          echo get_permalink( $prev_id );
      }
    echo "'>";   
    
    the_post_thumbnail( 'photoblog', array('alt' => ''.get_the_title().'', 'title' => ''.get_the_title().'' ));
    
    echo "</a>";
    
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘return URL only of next/prev post’ is closed to new replies.