Show One WordPress Post

There is a great function you might be aware of that allows you to get one WordPress post and display it anywhere you would like (header, sidebar, home page, etc).

To show only one post, use the function get_post.

Example:

PHP:
  1. <?php $sdac_post_id = 10;
  2. $show_post_id = get_post($sdac_post_id);
  3. $sdac_title = $show_post_id->post_title;
  4. $sdac_content = $show_post_id->post_content;
  5. ?>
  6. <h2><?php echo $sdac_title; ?></h2>
  7. <?php echo $sdac_content ?>

The code above will show the title and content of the post with the post ID of 10. If you are not sure what your post ID is, go to the manage screen in the WP-Admin, and hover over the post title. In your browser status bar, you will see the URL - and the post ID is the number at the end of the URL.

6 Responses to “Show One WordPress Post”

  1. Adriano says:

    I was looking to something like this , but I have adoubt , to add a READ MORE , how can be done thisn??

    THnaks!!

  2. jzelazny says:

    Are you looking for the read more to be added when you add in a MORE tag or do you want to hard code it?

  3. Adriano says:

    Hey Hi.. thanks for the Answer.!

    well I eman harecoded , for example :

    [code]
    1.
    post_title;
    4.
    $sdac_content = $show_post_id->post_content;
    5.
    ?>
    6.

    7.

    [/code]

    Adding to the above code the possibility to get the read more if it is one..

    is it possible… ?

    thanks

  4. Danny says:

    Hi
    great post!
    I was looking for that
    however.. I have a question:
    I was using contact form 7 plug in and
    put it in a post. then.. tried to show the form on
    my homepage using your method and for some reason it won’t work.
    simple post worked fine but plug in not.
    any idea? any addition to the code?
    thanks

  5. Peter V. says:

    Thanks Jennifer! So much more succinct and complete than the Wordpress codex entry on this function.

  6. Mobile says:

    Hi!,

    I want to show complete post while opening RSS feed of my blog (http://www.cheapmonthlymobile.co.uk/blog/). How can i do that? I already enabled “Full Text” option in reading section, but doesn’t works? Help Me!!!

Leave a Reply