Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm creating shortcode [latest_post] and want to show post date, title and short content. (content has "more" separator). Here is code:

function shortcode_latest_post() {
    global $post, $more;
    $tmp_post = $post;
    $tmp_more = $more;

    $posts = get_posts(array('numberposts' => 1, 'post_status' => 'publish'));

    $output = "";
    foreach($posts as $post) {
        setup_postdata($post);
        $more = 0;
        $output .= '<div class="latest_post">';
        $output .= '<span class="date">'. get_the_date() . '</span>';
        $output .= '<h3><a href="'. get_permalink() .'">'. get_the_title() .'</a></h3>';
        $output .= get_the_content("Read more...");
        $output .= "</div>";
    }
    $post = $tmp_post;
    $more = $tmp_more;
    return $output;
}
add_shortcode("latest_post", "shortcode_latest_post");

But I have problem with "get_the_content" function. It returns full content text instead of short text and more link.

Can anybody help me, please?

Update:

I'm found solution. Code above is updated. - http://codex.wordpress.org/Customizing_the_Read_More#How_to_use_Read_More_in_Pages

share|improve this question
add comment

1 Answer

get_the_content() does what it's supposed to, gets the content. You're looking for get_the_excerpt(). ;)

Alternatively, using what you have, it should cut off wherever you put <!-- more --> in your post when using get_the_content().

share|improve this answer
    
Thanks, but that is not what I want. After some researching, I'm found solution and updated the question. –  sasa Mar 29 '12 at 18:38
3  
@sasa You should post your solution as an answer and then accept it as the best answer. :) –  Jared Mar 29 '12 at 20:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.