WordPress.org

Ready to get started?Download WordPress

Forums

link to most recent post (2 posts)

  1. veevee
    Member
    Posted 6 years ago #

    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.

  2. veevee
    Member
    Posted 6 years ago #

    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

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

    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...

Topic Closed

This topic has been closed to new replies.

About this Topic