• lisadamus

    (@lisadamus)


    Hi, I want to show the excerpt of a page ( not post) in the home page. I used this code

    <?php
    $page_id = 2;
    $page_data = get_page ( $page_id );
    $content = $page_data->post_content;
    echo apply_filters( 'the_content', $page_data->post_content );?>

    and it works good, but it shows all the content and I want just the excerpt.
    I already tried to change content with excerpt, but it doesn’t work.
    Can someone help me, please?
    Thanks a lot

Viewing 4 replies - 1 through 4 (of 4 total)
  • canah

    (@canah)

    Here you are the codex and examples: the_excerpt

    Thread Starter lisadamus

    (@lisadamus)

    Thanks, but I already saw this link. It explains how to use excerpt for the post. I need excerpt for the text of a page.

    canah

    (@canah)

    Ok, so you can use substr in php to limit the characters, if it solves your problem.

    <>php 
    
    $page_id = 43;
    $page_data = get_page( $page_id );
    $content = $page_data->post_content;
    
    echo "<div id='name'>";
    echo substr( $content, 0, 100);
    echo "</div>";
    
    ?>

    This line describes your limit and instead 100 you can use any value:

    echo substr( $content, 0, 100);

    Thread Starter lisadamus

    (@lisadamus)

    Thank you very much. It works good !!!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘lenght words in home page’ is closed to new replies.