• i try to follow this wordpress wiki https://codex.www.ads-software.com/Function_Reference/get_page
    for put on my home page the excerpt of some post, with this code i put on my home page the content

    <?php
    $page_id = 424;
    $page_data = get_page( $page_id );
    $content = $page_data->post_content;
    $title = $page_data->post_title;
    echo $page_data->post_content;
    ?>

    then with (theorically) I put the excerpt on the home page, but nothing,

    <?php
    $page_id = 424;
    $page_data = get_page( $page_id );
    $content = $page_data->post_content;
    $title = $page_data->post_title;
    $excerpt = $page_data->post_excerpt;
    echo $page_data->post_excerpt;
    ?>

    where is the mistake?the function is in the codex so it should go ??

    kikko088

Viewing 6 replies - 1 through 6 (of 6 total)
  • Does the page have an excerpt entered into the excerpt field?

    If there’s nothing in the excerpt field for that page, you’ll see just that, nothing!.. ??

    You could use something like this instead..

    <?php global $post; $myposts = get_posts('post_type=page&include=424'); ?>
    <?php foreach( $myposts as $post ) : setup_postdata( $post ); ?>
        <?php the_excerpt(); ?>
    <?php endforeach; wp_reset_query(); ?>

    https://codex.www.ads-software.com/Template_Tags/get_posts

    Using get_posts() and setup_postdata() should allow the use of the_excerpt() which will return content even if you’ve not used the excerpt field.. ??

    NOTE: Despite the name, get_posts() can return any post_type, not just posts.. (and it supports more parameters then the get_page eqivalent).

    Thread Starter kikko088

    (@kikko088)

    yes i create an excerpt field with some word but nothing, your code is perfect, now I have to add the possibility to have random subpage of a page.
    I don’t know that get_post return also page, i think that return only posts, thank you very much!

    excuse me for my bad english ??
    kikko088

    Thread Starter kikko088

    (@kikko088)

    now i put on the code the parent and random,but i have only a question, to have the link to complete post instead the “[…]” what I have to do?
    thank you very much.

    kikko088

    add this code in your functions.php

    add_filter('wp_trim_excerpt', custom_excerpt);
    function custom_excerpt($text) {
      $text = str_replace('[...]', '<a href="' . get_permalink() .'">..complete post</a>', $text);
      return $text;
    }

    Thread Starter kikko088

    (@kikko088)

    thank you!

    In WP 2.9+ you can use excerpt_more instead of wp_trim_excerpt:

    add_filter('excerpt_more', 'custom_excerpt');
    function custom_excerpt($custom) {
    	return '<a href="' . get_permalink() .'">..complete post</a>';
    }

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘post excerpt’ is closed to new replies.