1. There is going to be scheduled downtime in the next few hours.

    We are physically moving servers and equipment to a data center that will give us 50x more bandwidth.
  2. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

the_permalink php not working

Discussion in 'WordPress' started by sixrfan, Feb 20, 2011.

  1. #1
    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>
    $latestposts = get_posts('numberposts=1&category=1');
    foreach($latestposts as $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???

    FYI, i did post practically the same issue here but that technique doesnt seem to be working on this site.
    please advise. thanks.
    sixrfan, Feb 20, 2011 IP
  2. Dodger

    Dodger Peon

    Likes Received:
    Best Answers:
    Trophy Points:
    Using the_permalink() can only be used within the Loop. Try this instead:

    <h3><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></h3>
    Code (markup):
    Dodger, Feb 20, 2011 IP
  3. sixrfan

    sixrfan Active Member

    Likes Received:
    Best Answers:
    Trophy Points:
    that worked.

    the force is strong with this one. thanks!!!
    sixrfan, Feb 21, 2011 IP