WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Link to newest post? (3 posts)

  1. Kevin Kwok
    Member
    Posted 4 years ago #

    I'm trying to link my visitors to my newest post on my website. I want them to view the post in their entirety but I have been searching and searching for a day now and cannot find the solution.

    I found this code on the forums but it only displays info such as date and title of the newest post.

    <?php $postslist = get_posts('numberposts=1'); ?>
    <?php foreach ($postslist as $post) : setup_postdata($post); ?>
    <li class="lnk2">
      <?php the_date(); ?><br /><?php the_title(); ?>
    </li>
    <?php endforeach; ?>

    Does anyone have a solution? =(

  2. mtw28
    Member
    Posted 4 years ago #

    Use the_content() to print the full post, you can replace your code with the following:

    <?php $postslist = get_posts('numberposts=1'); ?>
    <?php foreach ($postslist as $post) : setup_postdata($post); ?>
    <li class="lnk2">
      <?php the_date(); ?><br /><?php the_title(); ?><br /><?php the_content(); ?>
    </li>
    <?php endforeach; ?>

    If you just want to link to the post, try this:

    <?php $postslist = get_posts('numberposts=1'); ?>
    <?php foreach ($postslist as $post) : setup_postdata($post); ?>
    <li class="lnk2">
      <?php the_date(); ?><br /><a href="<?php the_permalink();?>"><?php the_title(); ?></a>
    </li>
    <?php endforeach; ?>
  3. Kevin Kwok
    Member
    Posted 4 years ago #

    GENIUS! my savor thank your sir! works perfectly =) thank you again

Topic Closed

This topic has been closed to new replies.

About this Topic