• Hi,

    I’m using the following code to display the most recent post on my static homepage. It appears that “the_permalink” and “the_title” aren’t working – I only see the page title (Home) and the page link (www.thinkbicycles.org/)

    How do I get it to display the post’s title and URL instead?

    <?php
    $previous_posts = get_posts(‘numberposts=1’);
    foreach($previous_posts as $post) :
    setup_postdata($post); ?>
    “><?php the_title(); ?>
    <?php the_excerpt(); ?>
    <?php endforeach; ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter browngrapevine

    (@browngrapevine)

    Sorry – the code didn’t display correctly in my last e-mail:

    <?php
    $previous_posts = get_posts('numberposts=1');
    foreach($previous_posts as $post) :
    setup_postdata($post); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php the_excerpt(); ?>
    <?php endforeach; ?>

    EDIT: at first use the wp_reset_query() and global post function

    Thread Starter browngrapevine

    (@browngrapevine)

    thanks for your fast comment. I just tried that, and it didn’t change the title/link that’s displayed.

    what is yor code now?

    Thread Starter browngrapevine

    (@browngrapevine)

    Thank you! Adding “global post” function to the code seems to do the trick. I now see the correct post title/link. However, now the “comments” box appears at the bottom of the post excerpt, even though the “Comments” box for the homepage has been disabled. Any suggestions why that is happening?

    Here’s my code now:
    <?php wp_reset_query(); ?>
    <?php
    global $post;
    $previous_posts = get_posts('numberposts=1');
    foreach($previous_posts as $post) :
    setup_postdata($post); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php the_excerpt(); ?>
    <?php endforeach; ?>

    by default “Comment Box” should not show on home page. It will be coming on page.php, single.php page only. check that have this type of code global $withcomment;

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘get_posts() and permalink – only showing page title/link, not post title/link’ is closed to new replies.