WordPress.org

Support

Support » Installation » [Resolved] how can i show specific excerpt on a page?

[Resolved] how can i show specific excerpt on a page?

  • steve from breathe4u
    Member

    @steve-from-breathe4u

    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 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • Edward Caissie
    Theme Review Admin, The JellyBeen Man

    @cais

    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>";

    steve from breathe4u
    Member

    @steve-from-breathe4u

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

    Edward Caissie
    Theme Review Admin, The JellyBeen Man

    @cais

    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 …

    steve from breathe4u
    Member

    @steve-from-breathe4u

    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.

    steve from breathe4u
    Member

    @steve-from-breathe4u

    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

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] how can i show specific excerpt on a page?’ is closed to new replies.