Forums

[resolved] get_posts link not working (2 posts)

  1. goldmember
    Member
    Posted 1 year ago #

    at the bottom of the homepage here I have the following code which reproduces the most recent post from category 1 on the homepage:

    <h2>The Latest at Cornerstone Antiques</h2>
    
    <?php
    $latestposts = get_posts('numberposts=1&category=1');
    foreach($latestposts as $post) :
       setup_postdata($post);
    ?>
    <h3><a href="<?php the_permalink(); ?>"><?php echo $post->post_title; ?></a></h3>
    <?php the_content(); ?>
    <?php endforeach; ?>

    but if you hover over the hyperlink for the post title you'll notice it just links back to the homepage and not to that particular post. I've tried similar code in multiple sites and there always seems to be a different variation of the code to make this work.

    so anyway...how do i get the post title that appears on the homepage to actually link to that post???

  2. goldmember
    Member
    Posted 1 year ago #

    got it figured out. have to use this instead.

    <h3><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></h3>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.