Support » Plugins » Widget to display one specified post

  • There must be a widget to do this somewhere but I can’t find it. I need a widget that will display a post in it, not a category etc but one single specified post. Ie the post with the ID of 71 will display and only that one, if thats the ID number entered.

Viewing 2 replies - 1 through 2 (of 2 total)
  • OK, five minute job. No error checking, no styling, no nothing.
    Use at your own risk.
    Create a new file displaypost.php in your wp-content/plugins directory.
    Paste the code below into it.
    Activate the plugin.
    Drag the widget to your sidebar.
    Enter the desired post ID and Bob’s your uncle (I always wanted to use that phrase :))


      Plugin Name: Display Post
      Plugin URI: http://localhost/wordpress
      Description: Display the content of a single post in a widget.
      Author: Christian Schmitt
      Version: 1
      Author URI: http://localhost/wordpress/
    class DisplayPost extends WP_Widget
        function DisplayPost()
            $widget_ops = array('description' => "Display the content of a single post in a widget.");
            $this->WP_Widget('displaypost', 'Display Post', $widget_ops);
        function widget($args, $instance)
            $postId = $instance['postid'];
            $thePost = get_post($postId);
            echo $before_widget;
            echo $before_title . $widget_name . $after_title;
            echo $thePost ? $thePost->post_content : "Invalid post ID!";
            echo $after_widget;
        function update($new_instance, $old_instance)
            $new_instance = (array) $new_instance;
            $instance['postid'] = strip_tags($new_instance['postid']);
            return $instance;
        function form($instance)
            $instance = wp_parse_args((array) $instance, array('postid' => -1));
            $postid = esc_attr($instance['postid']);
                <label for="<?php echo $this->get_field_id('postid'); ?>">Post ID</label>
                <input type="text"
                       id="<?php echo $this->get_field_id('postid'); ?>"
                       name="<?php echo $this->get_field_name('postid'); ?>"
                       value="<?php echo $postid; ?>" />
    function displaypost_init()
    add_action('widgets_init', 'displaypost_init');

    Thanks for that cschmitt – looks great. I found a work around solution that did the job for me in the meantime. I installed the Executable PHP widget and then used the following code to pull in the desired post:

    $post_id = 71;
    $queried_post = get_post($post_id);
    <div class=”specified-post”><?php echo $queried_post->post_content; ?></div>


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Widget to display one specified post’ is closed to new replies.