So have you ever wanted to display the current page’s excerpt in the sidebar as a widget? Well, this morning a similar situation arose on how to do this within the Twitter-verse. So, there a couple of us sat thinking and trying to assist in anyway possible. Anyways after a few minutes going back and forth, we had a couple of solutions and one which I coded very quickly into a WordPress Sidebar Widget. The steps taken to find and solve this problem:

  • Where is the widget going to be used? The widget with the excerpt should be displayed in the sidebar on single pages and posts.
  • Does the Widget need to be installed as a plugin? Or can it simply be an addition to the functions.php of the theme? I decided to be very lazy and coded it directly into the functions.php file of the themes.

After identifying and answering the questions above, I came up with the following solution:

function amcgowanca_widget_show_excerpt() {
    if( have_posts() && (is_single() || is_page()) ) {
        echo '
  • '; echo '

    ' . __('Summary') . '

    '; the_excerpt(); echo '
  • '; } } register_sidebar_widget('Show page & post excerpt', 'amcgowanca_widget_show_excerpt');

    Therefore, to implement and use this widget follow the steps below:

    • Copy the above code to your clipboard and paste it into the functions.php file at the bottom (remember to save the file).
    • Log in to the WordPress administrative control panel (/wp-admin/) and browse to your ‘Widgets’ panel.
    • Simply click, drag and drop the ‘Show page & post excerpt’ function into the sidebar of your choice.

    Notes:

    • The above code is will not work appropriately with Thematic. Therefore, remove the ‘have_posts() &&’ portion of the if() condition.
    • The above source code is licensed under the GNU general public license
    • If you have any problems and or questions, please use the comments below to ask and share.