Support » Fixing WordPress » link to most recent post

  • Okay, I’ve been doing a lot of searching, but I can’t find an answer to my question, which is this:

    How do I make a link to the most recent post of a specific category?

    I have a couple of categories, drawing, prints, etc. From inside of a single post, I want to make a link that dynamically takes the user to the newest drawing, or the newest print, etc. Most of the plugins or php out there relates to pulling shorts from the most recent entries onto the home page. I want a link to the full post itself. I think i know enough so that if someone knew how to, for example, get the ID for the most recent post in ‘drawings’ I could just plug it into:
    <a href=" <?php get_permalink(id); ?> ">Drawing</a>

    Right? Thanks in advance.

Viewing 1 replies (of 1 total)
  • Okay, so this is what I have; using the php to show recent posts, I use the the_permalink in an <a href> tag instead of the_content

     global $post;
     $myposts = get_posts('numberposts=1&offset=0&category=5');
     foreach($myposts as $post) :
    <div class="post" id="post-<?php the_ID(); ?>">
    	<a href="<?php the_permalink() ?>" rel="bookmark">Drawings</a>
     <?php endforeach; ?>

    This will make a link to the latest post in category #5 (see that, on the 4th line?) and display a link titled Drawings. This works for me because i only have 5 categories. If I constantly wanted to add categories, it would be annoying to paste this code over and over. Maybe someone can figure out a way to do it dynamically…

Viewing 1 replies (of 1 total)
  • The topic ‘link to most recent post’ is closed to new replies.