• I’ve got a temp file that I’m building as my new start page. (The blog is at https://www.mountyscorner.com/blog/index.php and the temp start page is at https://www.mountyscorner.com/test.php.) On the test file, I’ve got the five most recent posts listed. I’d like to be able to get the excerpts from those posts, but there is no default excerpt for the post. I edited the hack on the wiki to display excerpts after the post name. I’m sure it works (I’ve tested out putting in a 100-character excerpt on one post, and it shows correctly). The question is, how do I get it to show the first x number of characters from the post if there isn’t an excerpt specified? (I tried using the <?php get_the_excerpt(); ?> command in my-hacks.php, but it gave me nothing.)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Just use <?php the_excerpt(); ?> in your test.php file. If an excerpt doesn’t exist, WP will create one. get_the_excerpt() is a function that returns, so it won’t do anything useful by itself.

    You were likely doing this:

    echo $post->the_excerpt;

    Which grabs the specified excerpt. You have to use the_excerpt() function to have it make one in case you haven’t provided one.

    Thread Starter tmountjr

    (@tmountjr)

    $exc = $post-><?php the_excerpt(); ?>;
    $output .= $before . "<a href="" . $permalink . "" rel="bookmark" title="Permanent Link: " . $post_title . "">" . $post_title . "</a>Excerpt: <?php the_excerpt(); ?>" . "" . $after;

    That’s what the two lines in my-hacks.php look like. It’s not returning anything at all. What I have (just returns an excerpt that already exists) is this:

    $exc = $post->post_excerpt;
    $output .= $before . "<a href="" . $permalink . "" rel="bookmark" title="Permanent Link: " . $post_title . "">" . $post_title . "</a>Excerpt: " . $exc . "" . $after;

    I found the field in the table that had the excerpt, so I included it in the SQL statement. I figured out how to assign it to another variable (I’ve never programmed PHP before) and include it in the string, so it works for any post that has an excerpt already.

    If it helps, I’m basing this right off the hack listed in the wiki.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘sql help for excerpts’ is closed to new replies.