WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how can i show specific excerpt on a page? (6 posts)

  1. steve from breathe4u
    Member
    Posted 4 years ago #

    hi there,
    does anyone have any idea how i can display a specific excerpt on my home page using the post id? the following code works but shows the whole post

    <?php
    $post_id = 43; // substitute the actual post ID for "2"
    $my_post = get_post($post_id);
    echo "<h3>$my_post->post_title</h3>";
    echo "<p>$my_post->post_content</p>";
    ?>

    i’d really appreciate any help thanks :)

  2. Edward Caissie
    Theme Review Admin
    Posted 4 years ago #

    Have a look at this page in the codex: http://codex.wordpress.org/Function_Reference/get_post

    I believe you can simply change:

    echo "<p>$my_post->post_content</p>";

    ... to:

    echo "<p>$my_post->post_excerpt</p>";
  3. steve from breathe4u
    Member
    Posted 4 years ago #

    thanks for your help, but unfortunately this doesn’t seem to work :(

  4. Edward Caissie
    Theme Review Admin
    Posted 4 years ago #

    I just tested your code with my suggested change and it worked fine on my test server ... in what fashion is it not working for you?

    Perhaps there are underlying issues? Possibly a link to your blog and the active theme would be helpful ...

  5. steve from breathe4u
    Member
    Posted 4 years ago #

    hi cais,

    thanks for all your help. the website i’m working on is for a client parts of the site are hidden as its under construction but a direct link is http://www.4sportsgolf.com/home/ (hopefully this will work) the theme is one i’m developing myself. (its my first attempt) so i may have made some mistakes (in fact i’m wondering if i need to put any code in the functions for this to work). the title and content code works fine but when i replace the content code with the excerpt code i get a title and an empty p tag. once again thanks for all your help and patience.

  6. steve from breathe4u
    Member
    Posted 4 years ago #

    hi cais,

    thanks for your help but i just solved i,t the excerpt was from a page not a post and i just installed a plugin that has solved the problem (PJW page excerpt).

    cheers
    steve

Topic Closed

This topic has been closed to new replies.

About this Topic