treehouse : what would you like to learn today?
Web Design Web Development iOS Development

wp_trim_excerpt?

  • Hi all,

    I'm struggling with an issue about the excerpt. What i've got, is the following.

    I've got an id of a page. And i want that specific page to be displayed on a particular place. But i don't want to show the full content of the post. I know what you're thinking, use the_excerpt!!! But that won't work in this case, so in my search i found the function wp_trim_excerpt(), and when you put some text into this function, it will give an excerpt of that text.

    Well that's what the reference guide of WP says, but i don't get the excerpt of the page, but the whole content.. Probably i'm using it one the wrong way. So, can someone give me a hand?

    This is the code:

    /* Get front-end block's */
    function yandt_content_block( $position ) {
    global $wpdb;
    $content = $wpdb->get_row( "SELECT * FROM wp_yandt_frontcontent_content
    WHERE
    name = '" . mysql_real_escape_string( $position ) . "'" );
    // Get the page by ID
    $ID = $content->content_id;
    $page = get_page( $ID );

    // Check the position
    $extraClass = '';
    if( $position == 'Midden' ) {
    $extraClass = 'middle-one';
    }

    // Build the block
    echo '<article class="one-third ' . $extraClass . '">
    <header class="one-third-header">
    <h1>' . $page->post_title . '</h1>
    </header>

    <div class="one-third-content">';

    // Check for a thumbnail
    if( has_post_thumbnail( $ID ) ):
    echo get_the_post_thumbnail( $ID );
    endif;

    // Show the excerpt of this page
    echo wp_trim_excerpt($page->post_content);

    echo '<a href="' . get_permalink( $ID ) . '" title="' . $page->post_title . '" class="read-more">Lees verder</a>
    </div><!-- .one-third-content -->
    </article><!-- .one-third-article -->';
    }