• Resolved chickspirit

    (@chickspirit)


    I’ve managed to get the title of my most recent post on my home page but would also like an excerpt of the post.

    I’ve searched the forums and found some solutions but nothing I’ve tried has worked.

    Dealing with a bit of funky code I don’t understand so can’t figure out how to incorporate the solutions I’ve found into the code I’ve got.

    Thanks for the help.

    https://ktotheatothei.com

    <?php $how_many=1; //How many posts do you want to show
    require_once('wp-config.php'); // Change this for your path to wp-config.php file ?>
    
    <?
    $news=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<li><a href=\"%s\">%s</a></li>", get_permalink($np->ID),$np->post_title);
    } ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • Looks like $np->post_excerpt would hold the excerpt.

    Thread Starter chickspirit

    (@chickspirit)

    Thanks Michael.

    Well at least I understand how the code works a little better.

    Unfortunately I put it in but it’s still not showing an excerpt.

    This is how I put it in.
    get_permalink($np->ID),$np->post_title,$np->post_excerpt);

    Is that correct?

    Thanks.

    It would be more like:

    printf ("<li><a href=\"%s\">%s</a> %s </li>", get_permalink($np->ID),$np->post_title,$np->post_excerpt);

    Related:
    https://us.php.net/printf

    Thread Starter chickspirit

    (@chickspirit)

    Sorry. I should have posted the entire line of code. I did have the first part you added minus the %s

    Hmm.

    Still not working. I feel like it must be something very simple since the post title is showing up.

    Code…the joy of my existence.

    I’ll keep trolling the search engines. But any additional help in the meantime would be awesome.

    You are typing something in the Excerpt field when writing a post…correct?

    Related:

    Excerpt
    Template_Tags/the_excerpt

    Thread Starter chickspirit

    (@chickspirit)

    Well at least I was right about it being simple. :o)

    Sorry I thought that it would automatically grab a default amount of the post if I didn’t specify anything.

    Thanks for your patience, Michael.

    All is lovely.

    Are you including this script in your index.php file? When I plug it in there, I get a Syntax error when the page loads.

    Thanks,
    Brian

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Excerpt of most recent post on static home page’ is closed to new replies.