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 have the following front-page template made:

enter image description here

In place of those large Lorem Ipsum blocks, I need to show an "excerpt" from a specific page to fill that box (a certain # of characters).

So my question is: how do I get a pages content in String format so that I can echo it out and trim down to a certain # of characters?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted
<?php

// would echo post 7's content up until the <!--more--> tag
$post_7 = get_post(7); 
$excerpt = $post_7->post_excerpt;
echo $excerpt

// would get post 12's entire content after which you
// can manipulate it with your own trimming preferences
$post_12 = get_post(12); 
$trim_me = $post_12->post_content;
my_trim_function( $trim_me );

?>
share|improve this answer
add comment

If you're in the loop do this:

<?php
$my_excerpt = get_the_excerpt();
if ( $my_excerpt != '' ) {
    // Some string manipulation performed
}
echo $my_excerpt; // Outputs the processed value to the page

Or if you have an ID, get the post then sue the post_excerpt member var

e.g.

$post = get_post( $post_id );
echo $post->post_excerpt;
share|improve this answer
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.