Support » Fixing WordPress » Get excerpt as variable?

  • jeremyduffy

    (@jeremyduffy)


    Is there a simple way to do that or will I have to look it up manually?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Roy

    (@gangleri)

    What is your question?

    Doodlebee

    (@doodlebee)

    Do you want a specific excerpt, the most recent one, or a random one…need a little more clarification please.

    jeremyduffy

    (@jeremyduffy)

    Given a specific post id, what’s the best way to get it’s excerpt into a variable? Querypost?

    Doodlebee

    (@doodlebee)

    $excerpt = get_the_excerpt();

    It has to be within the loop. If you want a specific post excerpt outside the loop:

    global $post;
    get_post(‘7’);
    $excerpt = $postid->post_excerpt;

    That’ll return the excerpt for the post with an ID of “7”.

    jeremyduffy

    (@jeremyduffy)

    Awesome and great detail doodlebee. Thanks!

    Use get_the_excerpt() function.

    EXAMPLE :<?php
    $myExcerpt = get_the_excerpt();
    if ($myExcerpt != ”) {
    // Some string manipulation performed
    }
    echo $myExcerpt; // Outputs the processed value to the page
    ?>

    for more check http://codex.wordpress.org/Function_Reference/get_the_excerpt

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Get excerpt as variable?’ is closed to new replies.