Get the content of a specific page (by ID)

  • 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 number of characters).

    How do I get a pages content in String format so that I can echo it out and trim down to a certain number of characters?

  • <?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 );
    
    ?>
    

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM