WordPress.org

Forums

Displaying URL for latest post from a category (6 posts)

  1. nimaha
    Member
    Posted 5 years ago #

    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.

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    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
    }
    ?>
  3. nimaha
    Member
    Posted 5 years ago #

    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.

  4. esmi
    Forum Moderator
    Posted 5 years ago #

    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
    }
    ?>
  5. nimaha
    Member
    Posted 5 years ago #

    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.

  6. nimaha
    Member
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic