WordPress.org

Support

Support » Plugins and Hacks » Displaying URL for latest post from a category

Displaying URL for latest post from a category

  • I’ve been having a hard time finding a plug-in that will display the URL (or the anchor text) of the latest (1) post from a set category. I see options to display a post or a portion of a post, but not the link.

    It seems like something should be out there and I’m just missing it. Perhaps this is simpler than I’m making it and a plug-in isn’t even necessary.

Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi

    @esmi

    Forum Moderator

    You could try using something like:

    <?php
    $latest = get_posts('showposts=1&category_name=Foobar');
    foreach ($latest as $posts) {
    	setup_postdata($post);?>
    	<a href="<?php the_permalink();?>"><?php the_title();?></a>
    	<?php
    }
    ?>

    Thanks for helping. When I tried that, it directed me to the folling page:

    http://www.domain.com/<?php the_permalink();?>

    I guess it’s not grabbing the link correctly. I actually had tried something similar last week and got the same result. Unfortunately, I don’t have a strong enough knowledge of PHP to understand why it would behave that way.

    esmi

    @esmi

    Forum Moderator

    Sorry – just spotted a mistake. $posts instead of $post. Try:

    <?php
    $latest = get_posts('showposts=1&category_name=Foobar');
    foreach ($latest as $post) {
    	setup_postdata($post);?>
    	<a href="<?php the_permalink();?>"><?php the_title();?></a>
    	<?php
    }
    ?>

    We’re getting closer. Now, I have a URL like this:

    www.domain.com/2009/08/<?php the_permalink();?>

    It added in the year and month although I guess that’s not right either.

    The link should read:

    www.domain.com/topics/<?php the_permalink();?>

    Does this make any sense to you? I wonder why it’s putting the permalink tag at the end of the URL. Doesn’t that tag output the entire URL? Thanks for your help on this.

    Whoops, ignore my note about the topics aspect. It should be 2009/08 so I just need to figure out why it is putting the php tag at the end of that URL.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Displaying URL for latest post from a category’ is closed to new replies.