Title: problem creating widget
Last modified: August 18, 2016

---

# problem creating widget

 *  [Aaron](https://wordpress.org/support/users/ergate/)
 * (@ergate)
 * [20 years ago](https://wordpress.org/support/topic/problem-creating-widget/)
 * Hi, I am trying to create a widget that will let me display the recent posts.
   I know this is already built in, but I want to customize what is displayed. So
   I thought I would make a widget that would display recent posts the way I want
   to see them. I have made the widget, but it does not show up in sidebar widgets.(
   Yes I did upload the widget, activated them etc etc) There is something wrong
   with my code but I dont know what to look for to fix it. I based this on the 
   recent entries code in the widgets plugin.
    My code is as follows:
 * `<?php`
 * // This gets called at the plugins_loaded action
    function widget_recentposts_init(){
 *  // Check for the required API functions
    if ( !function_exists('register_sidebar_widget')
   || !function_exists('register_widget_control') ) return;
 *  // This saves options and prints the widget's config form.
    function widget_recentposts_control(){
   $options = $newoptions = get_option('widget_recentposts'); if ( $_POST['recentposts-
   submit'] ) { $newoptions['title'] = strip_tags(stripslashes($_POST['recentposts-
   title'])); } if ( $options != $newoptions ) { $options = $newoptions; update_option('
   widget_recentposts', $options); } ?> <div style="text-align:right"> <label for
   ="recentposts-title" style="line-height:35px;display:block;">Widget title: <input
   type="text" id="recentposts-title" name="recentposts-title" value="<?php echo
   htmlspecialchars($options['title']); ?>" /></label> <input type="hidden" name
   ="recentposts-submit" id="recentposts-submit" value="1" /> </div> <?php }
 *  // This prints the widget
    function widget_recentposts($args) { extract($args);
   $title = __('Recent Posts'); $r = new WP_Query('showposts=10'); if ($r->have_posts()):?
   > <?php echo $before_widget; ?> <?php echo $before_title . $title . $after_title;?
   >
 *  <?php while ($r->have_posts()) : $r->the_post(); ?>
    <?php the_excerpt(''); ?
   > <div class="entry"> <?php the_content('Read the rest of this entry &raquo;');?
   > </div>
 *  <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('
   Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »','%
   Comments »'); ?></p>
    <?php endwhile; ?>
 *  <?php echo $after_widget; ?>
    <?php }
 *  // Tell Dynamic Sidebar about our new widget and its control
    register_sidebar_widget('
   Recent Posts', 'widget_recentposts'); register_widget_control('Recent Posts','
   widge_recentposts_control');
 * }
 * // Delay plugin execution to ensure Dynamic Sidebar has a chance to load first
   
   add_action('plugins_loaded', 'widget_recentposts_init');
 * ?>

Viewing 1 replies (of 1 total)

 *  Thread Starter [Aaron](https://wordpress.org/support/users/ergate/)
 * (@ergate)
 * [20 years ago](https://wordpress.org/support/topic/problem-creating-widget/#post-393284)
 * Ok, I forgot one thing, to activate this widget in the plugin menu. That being
   done, I am now recieving this error
    `Parse error: parse error, unexpected '}'
   in /home/httpd/xxx/xxx/httpdocs/alog/wp-content/plugins/widgets/recent_posts.
   php on line 57`

Viewing 1 replies (of 1 total)

The topic ‘problem creating widget’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [Aaron](https://wordpress.org/support/users/ergate/)
 * Last activity: [20 years ago](https://wordpress.org/support/topic/problem-creating-widget/#post-393284)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
